The creation of Portugal was nothing short of a miracle which was accomplished by a single man, Afonso Henriques (1109-1185), known as Alfonso Henry in English. His deeds are best known from the massive tomes of the De Antiquitatibus Lusitaniae of Andre de Resende.
Prior to the time in question, almost all of Spain including what is now Portugal, belonged to Moslems from northwest Africa. Arabs, carrying with them the religion of Mohammed, invaded Africa and united with the Berbers there under this creed, creating a terrifying and determined force which had conquered Spain. This domination was not shaken until about 1070 when Rodrigo Díaz de Vivar known as "El Cid" began defeating the Moslems using combined Christian/Islamic armies. This was the pivotal point in the recapture of Spain from the Moslems, known as the Reconquista.
In the wake of El Cid's successes, King Alfonso VI of Leon capitalized on the situation and began conquering Spain. Alfonso was descended from ancient Visigothic invaders of Spain who had long resisted the Moslems from mountainous hideouts. Alfonso VI had won battles in western Spain all the way to Lisbon, but the territory, at his death, was still contested heavily. He chose a foreigner, a Norman knight, Henry son of Robert of Burgundy, to try to fight for this territory. To seal the deal, he married Henry to his bastard daughter, Theresa.
Following the death of Alfonso VI the Christian princes of Spain fell into intrigues and civil wars, during the course of which Henry died. The throne of Leon eventually fell to 18-year-old Alfonso Raymond, the son of another Norman knight and Urraca, one of the legitimate daughters of Alfonso VI. Theresa eventually accepted Alfonso Raymond, and to all appearances it seemed her territory would be added to the Kingdom of Leon, but this is not what happened.
Unexpectedly, abandoning and defying his mother, Alfonso Henry, at age 14, the ur-cousin of Alfonso Raymond, and sole son of Theresa began to fight. Theresa was assigned an army and went south to chastise her uppity son, but was met with a suprise. Alfonso gathered to himself all the local men and knights of their small realm and met her forces in battle at the field of Saint Mamede (1128) where he totally defeated them at age 18, despite being heavily outnumbered. Immediately after the battle he chased after the Galician camp, overtook it, seized his mother and threw her in a dungeon.
War then simmered for several years between the two cousins, both of them also fighting the Moslems. Henry built a castle at Celmes, but Raymond captured it and many of Henry's knights with it. Around the same time Alfonso of Aragon (yes, everybody was named Alfonso), Raymond's greatest rival, was killed by the Moors. In 1135, Raymond was declared emperor. It appeared the short rebellion was over and Henry would have to give up.
Nevertheless, Henry would not yield. While Raymond was busy with other wars, Henry kept fighting. At this juncture, the Moors decided to make one, last, great stand against the Christians, and they would begin by obliterating the upstart prince Henry. Gathering a huge force, the Saracens advanced on the small boundaries of Henry's duchy and the battle was fought in 1139 at Ourique. Defying all the odds, Henry crushed the Moorish forces commanded by five separate kings, all of whom he defeated. After this huge victory the knights of the realm declared Alfonso Henry KING OF PORTUGAL for the first time.
Now, Alfonso Raymund saw that his upstart cousin was truly a threat. Only a few years previously it seemed Henry would be just a distant memory, now all of Christendom was calling him a king. Raymund decided to make one last test of the nascent kingdom. He assembled a huge army and marched to Portugal, but rather than slaughter each other, they decided it would be a contest between knights. All the hundreds of knights of both sides lined up and fought one against the other in single combat to determine the winner. By the end of the bloody tournament, the Castilians decided the Portuguese had fought worthily and Raymund conceded. The result was formalized two years later by the Treaty of Zamora (1143). Portugal as we know it was born.
Didn't they teach this to you at school?