The village of Rio de Janeiro was founded in 1565 by the Portuguese near Sugar Loaf Mountain as a stronghold to defend the territory against foreign invaders after the expulsion of French settlers. The full name of the city, São Sebastião do Rio de Janeiro, was a tribute to the Portuguese king (and, of course, the saint). In 1567, when the village was moved to Morro do Castelo, the population amounted to some 3,000 people, most of them indigenous. The main industries at that time were fishing, especially whale fishing, and sugar production, with large sugar cane plantations and processing plants that extended from Gávea and the Rodrigo de Freitas Lake to the suburbs.
At the end of the 17th century, the gold rush in Minas Gerais, northwest of Rio, gave a boost to the city's development. There was a substantial increase in immigration from Portugal that turned the city into the main port of the colony. This, in turn, attracted a legion of French pirates and smugglers, who invaded the city in 1710 and 1711, until they were finally expelled. The city boomed and the increase in population forced the frantic development of infrastructure to keep up. The most famous aqueduct in Rio, the Lapa Arcs, was opened in 1793. The structure is so solid that it is used today as a tramway connecting the district of Santa Teresa to the city centre.
The arrival of the Portuguese royal family in 1808 turned Rio into the temporary capital of Portugal, and the population increased to 70,000 people. It was at this time that the city began to develop its characteristic division between rich and poor districts. The more affluent families established themselves in the areas between the sea and the hills, known today as the Zona Sul, and the poorer families went beyond the hills to the Zona Norte. It was around this time that the Botanical Garden, the Casa França-Brasil, the Royal Library and the Customs House were built.
In 1815 Rio de Janeiro was officially declared the capital of Brazil. In 1821 the royal family moved back to Portugal, leaving Prince Dom Pedro I to rule the colony. In 1822, after rebelling against orders to return to Portugal, Dom Pedro I declared Brazil independent from Portugal, and became the first Emperor of Brazil. The building known as Paço Imperial became his palace.
The first congressional assembly in Brazil was created in Rio in 1823 and met where the Tiradentes Palace now stands. In 1831, Dom Pedro I abdicated, but his son, Dom Pedro II, was not recognized as the ruling emperor until 1840 due to his young age. It was under Dom Pedro II that Rio de Janeiro underwent significant improvements. Between 1854 and 1862 the city received gas lighting, water and sewage services and transatlantic wire and telephone systems. Transport was also advancing, with the appearance of trams, trains and ferry boats. In 1884 the railway that runs up the Corcovado hill was inaugurated, and the opening, in 1892, of the tunnel between Botafogo and Copacabana initiated the migration of the more affluent families to the coast. The end of slavery in 1888 and the extinction of the monarchy in 1889 brought significant growth the manufacturing industry, with a matching decline in agriculture.
The early 20th century brought many improvements to the city center, with the opening of Rio Branco and Beira-Mar Avenues and the construction of the Municipal Theatre, the Arts School and the National Library. In the thirties and forties the population spread along the shore, occupying the areas of Ipanema and Leblon, and the skyscrapers started to fill the landscape of the residential districts as well as the city centre.
In the sixties the capital was transferred to Brasilia, though Rio remained the cultural capital of Brazil and the political capital of the Guanabara state. In the sixties and seventies there were big changes to the landscape of Rio, with the creation of the Aterro do Flamengo, the opening of tunnels connecting the South and the North, the Rio-Niterói bridge and the underground.
In 1975 Guanabara State was replaced by the state of Rio de Janeiro, of which Rio, not surprisingly, became the capital.