He retained the office of Foreign Minister until December 28, 1839. Bonfim’s administration, in which he combined the posts of Prime Minister, Minister of War, and head of the Colonial Department, lasted to June 9, 1841. Among those taking office in his ministry were Costa Cabral, Rodrigo da Fonseca Magalhães and others. It was during the period of his government that various European powers (among them, the Holy See) resumed diplomatic relations with Portugal, having broken them off after the arrival of the constitutional regime. He especially cultivated friendly relations with Spain after the tensions of the Carlist War. He was responsible for the foundation in July 1840 of the fortress and town of Mossâmedes in southern Angola and he promoted internal pacification in Portugal. On December 26, 1840, Portugal and the United States of America signed a Mutual Treaty of Commerce and Navigation. Bonfim resigned the premiership when he encountered resistance to his plans to reform the National Guard, and was succeeded in office by Joaquim António de Aguiar, who had been his deputy. After the "coup d'état" of 1842, which brought the Costa Cabral government to power, the Count of Bonfim became its most implacable opponent. In 1844 he raised the standard of rebellion against Costa Cabral's dictatorial policies but his associates were imprisoned or forced to flee the country and he himself left Portugal until the rebellion of Maria da Fonte in 1846. When the anti-Cabralist government of the Duke of Palmela took office Bonfim returned to Portugal, but in October the palace coup known as the Emboscada brought a new government of Cabralist sympathies to power, headed by the Duke of Saldanha. In the ensuing 'Little Civil War' or Patuleia, Travassos Valdez supported the revolutionary Junta of Porto against the more conservative forces around the Queen and took command of the 'Progressista' army. Expected reinforcement from the troops commanded by the Conde of Antas, the President of the Junta, was not forthcoming in time, and Bonfim and his army were besieged by Saldanha in the fortress of Torres Vedras and defeated, December 22–23, 1846. In violation of their safe-conduct, Bonfim, his two eldest sons and various political associates were exiled to Moçâmedes in southern Angola. He escaped from there with his sons in a skiff, intending to sail to Saint Helena, but was recaptured; the safe return of the exiles by the British Royal Navy and their honourable reinstatement was a condition of the Peace negotiated by the Four Powers at the Convention of Gramido, 1847.