He began his political career in 1874 with an election to the Imperial General Assembly. In the succeeding years, Pena reconciled legislative work with some periods occupying secretariats — secretary of Agriculture (1882), Commerce and Public Issues (1883) and Justice (1885). Pena then presided over the provincial assembly of Minas Gerais.
After the proclamation of the Republic, he was governor of Minas Gerais between 1892 and 1894. It was during his administration that Belo Horizonte was set for future state capital (which at that time was Ouro Preto).
In 1902 Pena became vice-president to Francisco de Paula Rodrigues Alves. He was elected president in 1906 and served until his death in 1909, a few days after the passing of his son Álvaro Pena.
Afonso Pena was the first Brazilian president to advocate intervening in the coffee economy. The federal government started to buy production surplus, thus maintaining the high price of coffee in international markets. Pena also promoted the expansion of railroads.