Elected as a Democrat to the Forty-fourth Congress, Bagley was a U.S. Representative for the fifteenth district of New York. He served from March 4, 1875 to March 3, 1877. He was not a candidate for renomination in 1876 and resumed his former mercantile pursuits. He was then elected to the Forty-eighth Congress, holding office from March 4, 1883 to March 3, 1885. During the Forty-eight Congress he was chairman of the Committee on Manufactures. Not a candidate for renomination in 1884, he engaged in banking and the insurance business and also served as vice president of the Catskill Mountain Railway Co.