After the rule of the Capitanias (land grants to Portuguese noblemen) had failed, Portugal hurried to appoint a General Government for Brazil. This government was intended to support the Donatários (the owners of the capitanias) and to unify them for common defense. The Portuguese crown acquired the Capitania de Todos os Santos (All Saints’ Capitania) from the poor heirs of Francisco Pereira Coutinho. This capitania was considered the most adequate place in Brazil to offer support to other villages and capitanias. The city of Salvador was built in this capitania and became Brazil’s first capital. In subsequent years, Brazil witnessed many fights while the rule was strengthened and possession of the land solidified.

During an extended period of time, the French dominated Guanabara Bay and the neighboring regions from Fortress of Villegaignon, from where they were only expelled after hard fights. Subsequent battles to expel them from Rio Grande do Norte, from Paraíba and from Maranhão were not easier. Just after Brazil had been liberated from the French, an even larger menace arose: The Dutch invasions. They posed a greater threat because they---as opposed to the French who used to occupy only regions not colonized by the Portuguese---attacked exactly the most important regions and cities of the time. They took them by surprise, looted them, and kept them occupied for long periods. The first conquered city was the capital itself, Salvador, the seat of the General Government.

Salvador had just defeated the English pirates, Robert Withrington and Christopher Lister, but it could not counter the 500 canons, 1,700 soldiers and 1,600 marines under the Flemish Admiral Willenkens. The expulsion of the Dutchmen from Salvador, one year later, was a vivid reminder that the Portuguese had to augment their troops if they wanted to command the land and keep it. The Dutch returned five years later, this time not with 23 ships as before, but with 70. They brought 7,200 soldiers and 1,200 canons, and landed in Pernambuco, one of the richest regions of the Portuguese colony. Olinda and Recife succumbed. From there, the invaders extended their dominion to the entire Northeast. During a quarter of a century, the Dutch lived there as landlords, accepted or even esteemed by many Brazilians. The foreign attempts to occupy Brazil came to a permanent end after the Dutch were defeated in the Guararapes Bay and capitulated at the battlefield of Taborda. However, the coastline was still not safe from pirate attacks. The pirates became ever more audacious, some were even sponsored by the governments of their home countries.

In 1591, the English pirate Thomas Cavendish looted the prosperous Capitania de São Vicente, and burnt the sugar cane farms (engenhos) and the village. In 1592, he attacked the villages of Santos at the coast of São Paulo state and Vitória at the coast of Espírito Santo state. Another English pirate, James Lancaster, and the Dutch Johan Vanner, had conquered the cities of Olinda and Recife in 1595 (before the Dutch invasion) and stayed there for a month while loading their 15 ships with the conquered products. They had stolen so much that they even had to rent three more Dutch ships, which were mooring at the port. In 1624, the Dutch conquered Salvador, the Capital. Even after their expulsion, they did not stop trying to re-conquer it. Pieter Heyn, who had participated in the conquest, came back in 1627, attacked the port and took 25 ships with their cargo. He and his men stayed for a month. The same Pieter Heyn had been involved in the fights over Vitória during the period of the Dutch domination of Bahia. The Dutch, who had settled in Pernanbuco, kept invading since 1630, and continued their attempts at conquering the seat of the General Government. Nassau himself commanded the expedition, in which 3,400 soldiers and 1,000 Indians participated on the Dutch side. He was beaten off. In 1710, the French Duclerc invaded Rio de Janeiro. He was defeated, and 450 of his men were killed by the enraged people. In revenge, another Frenchman, Duguay Trouin, attacked Rio again in the following year with more than 700 canons and 5,000 soldiers. This time, Rio could not resist and was looted. Trouin took 610.000 Cruzados (the currency at the time), 100 boxes of sugar and 200 bulls as a payment for not burning the city. Some historians allege that the plundering yielded 25 to 30 million Cruzados (currency at the time) to Trouin.