Stiles was elected as a Democrat to the Thirty-seventh Congress to fill the vacancy caused by the death of Thomas B. Cooper. He was reelected to the Thirty-eighth Congress. He was again elected to the Forty-first Congress. He was not a candidate for renomination in 1870. He resumed the practice of law and died in Allentown in 1896. Interment in Fairview Cemetery.