After the fall of the Roman Empire, the Visigoths ("Western Goths") overran the Roman provinces of Terraconensis and Baetica, which comprised North and South Spain. The Iberian peninsula was rent between various Visigothic Kingdoms from 410 onwards, and the peninsula would not be unified again for another 1000 years.
In 1516, Charles V inherited both the Kingdoms of Castile and Aragon from the Most Catholic Kings, Ferdinand and Isabella. The Catholic Kings had completed the reconquista by conquering Grenada and, to an extent, there was unity throughout most of the Iberian peninsula. Portugal, however, remained obstinate - and as the most south-western people in Europe, they were natural heirs to the old Arab art of exploring, which they took up with zeal. Possessing a large ocean-going Navy, they colonized diverse territories in the New World, Asia, and Africa, including Brazil. Despite their good positioning in Europe, it is a remarkable feature of the Age of Discovery that this small Kingdom could become so powerful. Throughout much of the 15th Century Portugal was secure, however, especially when compared to its powerful neighbour Castile, which was ridden with civil war. Portugal defeated the Castillian army at Aljubarrota 1385 and a permanent peace was established in 1411.
A series of Portugese Kings (Henry the Navigator being foremost in fame among them, if not in actual deeds) patronized seamen and explorers. They had a number of motives, not least of which was the so called "gold famine" of the late 14th and early 15th centuries. With no new gold coin being minted in Portugal, it was vital for them to reach sources in the New World. There was even a sort of Portugese "Manifest Destiny" - they saw themselves as lovers of liberty, spreading Christianity to the Infidels (who were generally loathed.) This view of themselves came from the myth that the Portugese people were direct descendents of the Lusitania, a tribe who rebelled against the Romans many centuries earlier.
As a nation of only one million people, it is perhaps not so surprising that Portugal had trouble maintaining its expansion and its status as a global power. Its efficacy was declining by the late 16th Century, and Philip II of Spain had designs on the Portugese throne. He had a claim through his mother Isabella of Portugal, and when in 1578 his nephew, King Sebastian of Portugal was killed in battle along with most of his high nobility at Alcazar, he saw a chance to actualize his plans. The Portugese King had died in combat against the Ottoman puppet ruler in Morocco - yet another victim of Christianity's crusading spirit. Philip II was himself starting to realize at this point that further conflict with the Porte was futile, and the Portugese "crusade" had complicated his attempts to bring about a peace between himself and the East.
Between 1578 and 1580, Portugal was ruled by the 66 year-old, blind and deaf Cardinal Henry. In a futile attempt to produce an heir, he married a 13 year-old daughter of a noble family. He died childless and having not designated a successor, and Philip was quick to move in. In 1579 he had established a committee to investigate his claims on the Portugese crown, and indeed his paper claim through his mother was very good. There were two other claimants to the crown, one of which would remain a problem after Philip had acquired it: one was Don Antonio, illegitimate son of Henry's brother, and the other was the Duchess of Braganza. Philip took decisive action on two fronts: the first was to send a minister to Portugal to gather support for his claim. He bribed nobles and members of the Cortes (legislative branch), paid the ransoms of nobles captured by the Ottomans in 1578, and got the Braganza faction onboard with a series of bribes and promises of power to come under his regime.
But another front proved necessary: the application of military force. Don Antonio's faction seized Lisbon upon Cardinal Henry's death in 1580, and he seemed to be welcomed by the commons. An army of 37,000 Spanish troops entered Portugal and made a bee-line for Lisbon, which was subdued by September of 1580. The mercantile culture of Portugal was fairly open to the advantages which unity with Spain would bring - trade routes over land through Castile and Aragon were now much easier. Some in the town oligarchies opposed Spanish control, and to appease them Philip was most prudent in his ruling of Portugal. Just as his father had offended the Spanish upon his arrival in Madrid and he himself had offended the Dutch, Philip knew that trying to impose outside customs on a foreign Kingdom was not a good way to rule it. He proclaimed to the Portugese that no foreigner would hold office in their land, that no external institutions would be imposed, and that their commercial monopolies would be respected. He cut his beard in Portugese fashion and dressed in their clothes while in the country between 1580 and 1583.
Having united the Iberian peninsula, Philip enjoyed enormous prestige. Many historians think this was the greatest achivement of his reign, and it was widely praised by contemporaries. Cardinal Granvelle even suggested that the capital of Philip's great Empire be moved to Lisbon because it was strategically placed for the battlefield of the next decades: the Atlantic Ocean. Portugal's large ocean-going fleet gave Philip immense sea power. Newly confident and with an augmented flow of bullion coming in from the New World, he would soon turn his attentions to England with the Spanish Armada. England's fear increased and she stepped up her campaigns against Catholicism. Pope Sixtus V and the Dutch denounced this act of "imperialism" and the Holy Father hilighted this as adamant proof of Philip's interest in temporal concerns above spiritual.
This, say the Spanish people, looking back at their history, is the zenith of the Golden Age of Spain. As ruler of 40 million people and an Empire on which the Sun never set, Philip II was probably the most powerful man in the world. It was in the 1580s that he began to call himself "King of Spain", rather than "King of Castile." There was no Western front from which to fear attack by an outside power, and the futile attempts of Don Antonio to take the throne of Portugal failed (despite the assisstance of France and England).
Spain's control of Portugal would only last until the 1640s, however - the Spanish Empire was in serious decline under King Philip IV, and the Portugese began to become infuriated that Spain was unable to provide security for its trade routes and the spice islands. Involved in a war in Catalonia, Spain was adding insult to injury by trying to tax Portugal more than normal to pay for it. In 1640, Portugese soldiers were asked to go to fight in Catalonia: they promptly went to fight in Lisbon, and installed the Duke of Braganza as King John IV. Spain could not send armies to try and subdue Portugal for another decade, and when they did go they failed. In 1668 Spain was forced to acknowledge Portugal as an independent state.