>>212596581 (OP)Brazil is the only former european colony in history to have hosted the seat of power of the colonial empire it originally belonged to, in a process some historians have called a ''metropolitan reversal''. When the French invaded and occupied Portugal during the Peninsular War the Portuguese Court and government relocated to Rio. The capital remained in Rio from the arrival of the Royal Family in 1808 until their return in 1821.
Bonus fact: in 1815 Brazil ceased to be a colony and gained equal status in the empire, and the State was renamed to United Kingdom of Portugal, Brazil and Algarves.
Second bonus fact: some historians argue that, from a legal and historical standpoint, the liberal revolutionary government led by the Cortes in Portugal in 1821 was actually the one to secede from the empire, since all relevant institutions remained in Rio. The ministries, secretaries and heir to the crown all remained in Rio, and had no intention of declaring Brazilian independence. There's actually a plethora of primary sources (mostly correspondence) that show beyond a shadow of doubt that the Court in Rio wished to remain in Rio and keep the colonial empire whole. Turning Brazil independent was a last resource when it became clear that the Cortes in Portugal had no intention of keeping the status quo.
Third bonus fact: the whole project of ruling the Portuguese empire from Rio was far from being a haphazard contingency measure due to Napoleonic invasion. As a matter of fact, the plan was first suggested by António Vieira, a Jesuit priest and relevant man of letters in the Portuguese language to this day, back in the 17th century. It would only be in the 18th century, however, that the plan would actually get to be fully developed by the Court, mostly due to the efforts of Rodrigo de Sousa Coutinho, Count of Linhares, and his party.