For 13 years, Portugal was ruled from Rio de Janeiro

In November 1807, with a French army a day from Lisbon, Portugal's royal family and court sailed for Brazil.
On November 29, 1807, a fleet sailed out of Lisbon carrying Portugal's royal family, its court and its senior officials. The next day a French army sent by Napoleon reached the gates of the city.
The man in charge was Prince John, who ruled in place of his mother, Queen Maria I, because she was mentally ill. Portugal was one of Britain's last allies on the continent. Two weeks earlier a British squadron had arrived at Lisbon with orders to escort the royal family to Brazil, or, if Portugal gave in to France, to attack the city. John chose Brazil.
They left in a hurry, in a rainstorm. John had posters put up telling people to stay calm and not to resist the invaders. He sailed on the same ship as his mother and his sons Pedro and Miguel, so one shipwreck could have ended the line of succession. At sea the fleet sat becalmed near the equator for ten days, rode out two storms and was scattered near Madeira.
In January 1808 John landed at Salvador, Brazil's first capital, and opened Brazil's ports to trade with friendly nations. Until then the colony had been allowed to trade only with Portugal. In March he reached Rio de Janeiro and made it his capital.
What is the capital of Texas?
WhyTexas built its capitol taller than the one in Washington. The Texas State Capitol in Austin stands about 300 feet tall and is faced with pink granite, which the owners of a nearby quarry donated.
Rio had few roads and no proper sewers. The court built palaces and government offices, a botanical garden and an opera house. Brazil got its first printing press, and John founded the Bank of Brazil. In 1815 he raised Brazil from a colony to a kingdom equal to Portugal, and the whole realm was renamed the United Kingdom of Portugal, Brazil and the Algarves. His mother died the next year, and in 1818 he was acclaimed king in Rio.
Portugal, meanwhile, was being governed without its king. In 1820 a liberal revolution broke out there, and John had to go back or risk losing his Portuguese throne. He sailed in April 1821 and left his son Pedro in Rio to rule Brazil.
Pedro had been nine years old when the fleet left Lisbon, and he had grown up in Rio. Portugal's parliament wanted Brazil turned back into a colony and Pedro brought home. On January 9, 1822, he was handed a petition with 8,000 signatures asking him to stay. "Tell the people that I am staying," he answered.
On September 7, 1822, Pedro declared Brazil independent of Portugal, his father's kingdom. That October he became the first emperor of Brazil.