Brazil

From 1808 to 1821, Rio de Janeiro, Brazil's second-largest city, was the capital of Portugal.

An excerpt from the article 31 facts about Brazil

The royal family headed by John VI (King of Brazil and Portugal) took refuge there from invading Napoleonic troops.