Fonseca took office as provisional president after heading a military coup that deposed Emperor Pedro II and established the First Brazilian Republic in 1889, disestablishing the Empire.
He was the son of Manuel Mendes da Fonseca Galvão (1785–1859) and his wife, Rosa Maria Paulina de Barros Cavalcanti (1802–1873).
Fonseca pursued a military career that was notable for his suppression of the Praieira revolt in Pernambuco in 1848, Brazil's response to that year's revolutions in Europe.
As Governor of Rio Grande do Sul, Fonseca was courted by republican intellectuals such as Benjamin Constant and Ruy Barbosa in the café society of São Paulo.
In 1886, alerted that the imperial government was ordering the arrest of prominent republicans, Fonseca went to Rio de Janeiro and assumed leadership of the army faction that supported the abolition of slavery in Brazil.
A group of deputies opposed the decision and found support among the high-ranking officers of the Navy, including Admiral Custódio José de Melo.