The first era of the Portuguese empire originated at the beginning of the Age of Discovery. Initiated by the Kingdom of Portugal, it would eventually expand across the globe. In the wake of the Reconquista, Portuguese sailors began exploring the coast of Africa and the Atlantic archipelagos in 1418–19, using recent developments in navigation, cartography and maritime technology such as the caravel, in order that they might find a sea route to the source of the lucrative spice trade. In 1488, Bartolomeu Dias rounded the Cape of Good Hope, and in 1498, Vasco da Gama reached India. In 1500, either by an accidental landfall or by the crown's secret design, Pedro Álvares Cabral discovered Brazil on the South American coast.
Over the following decades, Portuguese sailors continued to explore the coasts and islands of East Asia, establishing forts and factories as they went. By 1571, a string of naval outposts connected Lisbon to Nagasaki along the coasts of Africa, the Middle East, India and South Asia. This commercial network and the colonial trade had a substantial positive impact on Portuguese economic growth (1500-1800), when it accounted for about a fifth of Portugal's per capita income.
When Philip II of Spain, I of Portugal, inherited the Portuguese crown in 1580, this began a 60-year union between Spain and Portugal that has since been given the historiographic term of the Iberian Union. Though the realms continued to be administered separately, the Council of Portugal ruled the country and its empire from Madrid. As the King of Spain was also King of Portugal, Portuguese colonies became the subject of attacks by three rival European powers hostile to Spain: the Dutch Republic, England, and France. With its smaller population, Portugal was unable to effectively defend its overstretched network of trading posts, and the empire began a long and gradual decline. Eventually, Brazil became the most valuable colony of the second era until, as part of the wave of independence movements that swept the Americas during the early 19th century, it broke away in 1822.
The third era represents the final stage of Portuguese colonialism after the independence of Brazil in the 1820s. By then, the colonial possessions had been reduced to forts and plantations along the African coastline (expanded inland during the Scramble for Africa in the late 19th century), Portuguese Timor, and enclaves in India (Portuguese India) and China (Portuguese Macau). The 1890 British Ultimatum led to the contraction of Portuguese ambitions in Africa.
Under António Salazar, the Second Portuguese Republic made some ill-fated attempts to cling on to its last remaining colonies. Under the ideology of Pluricontinentalism, the regime renamed its colonies "overseas provinces" while retaining the system of forced labour, from which only a small indigenous elite was normally exempt. In 1961, Goa was annexed by India and Fort of São João Baptista de Ajudá was annexed by Dahomey (now Benin). The Portuguese Colonial War in Africa lasted until the final overthrow of the regime in 1974. The so-called Carnation Revolution led to the hasty decolonization of Portuguese Africa and the annexation of Portuguese Timor by Indonesia. Decolonization prompted the exodus of nearly all the Portuguese colonial settlers and many mixed-race people from the colonies. Portuguese Macau was returned to China in 1999. The only overseas possessions to remain under Portuguese rule, the Azores and Madeira, both had overwhelmingly Portuguese populations, and their constitutional status was subsequently changed from "overseas provinces" to "autonomous regions".
The origin of the Kingdom of Portugal lay in the reconquista, the gradual reconquest of the Iberian peninsula from the Moors. After establishing itself as a separate kingdom in 1139, Portugal completed its reconquest of Moorish territory by reaching Algarve in 1249, but its independence continued to be threatened by neighbouring Castile until the signing of the Treaty of Ayllón in 1411.
Free from threats to its existence and unchallenged by the wars fought by other European states, Portuguese attention turned overseas and towards a military expedition to the Muslim lands of North Africa. There were several probable motives for their first attack, on the Marinid Sultanate (in present-day Morocco). It offered the opportunity to continue the Christian crusade against Islam; to the military class, it promised glory on the battlefield and the spoils of war; and finally, it was also a chance to expand Portuguese trade and to address Portugal's economic decline.