These Germanic rulers seem never to have been popular with those they governed, so that when the great Moslem invasion crossed from Morocco in 711 and, defeating King Roderick at Guadalete near Cadiz, swept in an incredibly short time right up to the northern mountains, the whole country submitted with scarcely a struggle.

A few only of the Gothic nobles took refuge on the seaward slopes of the Cantabrian mountains in the Asturias and there made a successful stand, electing Don Pelayo as their king.

As time went on, Pelayo's descendants crossed the mountains, and taking Leon gradually extended their small kingdom southwards.

Meanwhile other independent counties or principalities further east were gradually spreading downwards. The nearest was Castile, so called from its border castles, then Navarre, then Aragon, and lastly the county of Barcelona or Cataluña.

Galicia, in the north-west corner, never having been thoroughly conquered by the invaders, was soon united with the Asturias and then with Leon. So all these Christian realms, Leon—including Galicia and Asturias—Castile, and Aragon, which was soon united to Cataluña, spread southwards, faster when the Moslems were weakened by division, slower when they had been united and strengthened by a fresh wave of fanaticism from Africa. Navarre alone was unable to grow, for the lower Ebro valley was won by the kings of Aragon, while Castile as she grew barred the way to the south-west.

At last in 1037 Fernando i. united Castile and Leon into one kingdom, extending from the sea in the north to the lower course of the Douro and to the mountains dividing the upper Douro from the Tagus valley in the south. Before Fernando died in 1065 he had extended his frontier on the west as far south as the Mondego, making Sesnando, a converted Moslem, count of this important marchland. Then followed a new division, for Castile went to King Sancho, Leon to Alfonso vi., and Galicia, including the two counties of Porto and of Coimbra, to Garcia.

Before long, however, Alfonso turned out his brothers and also extended his borders even to the Tagus by taking Toledo in 1085. But his successes roused the Moslem powers to fresh fanaticism. A new and stricter dynasty, the Almoravides,[2] arose in Africa and crossing the straits inflicted a crushing defeat on the Christians at Zalaca. In despair at this disaster and at the loss of Santarem and of Lisbon, Alfonso appealed to Christendom for help. Among those who came were Count Raymond of Toulouse, who was rewarded with the kingdom of Galicia and the hand of his daughter and heiress Urraca, and Count Henry of Burgundy, who was granted the counties of Porto and of Coimbra and who married another daughter of Alfonso's, Theresa.

This was really the first beginning of Portugal as an independent state; for Portugal, derived from two towns Portus and Cales, which lie opposite each other near the mouth of the Douro, was the name given to Henry's county. Henry did but little to make himself independent as he was usually away fighting elsewhere, but his widow Theresa refused to acknowledge her sister Urraca, now queen of Castile, Leon and Galicia, as her superior, called herself Infanta and behaved as if she was no one's vassal. Fortunately for her and her aims, Urraca was far too busy fighting with her second husband, the king of Aragon, to pay much attention to what was happening in the west, so that she had time to consolidate her power and to accustom her people to think of themselves as being not Galicians but Portuguese.

The breach with Galicia was increased by the favour which Theresa, after a time, began to show to her lover, Don Fernando Peres de Trava, a Galician noble, and by the grants of lands and of honours she made to him. This made her so unpopular that when Alfonso Raimundes, Urraca's son, attacked Theresa in 1127, made her acknowledge him as suzerain, and give up Tuy and Orense, Galician towns she had taken, the people rose against her and declared her son Affonso Henriques old enough to reign.

Then took place the famous submission of Egas Moniz, Affonso's governor, who induced the king to retire from the siege of Guimarães by promising that his pupil would agree to the terms forced on his mother. This, though but seventeen, Affonso refused to do, and next year raising an army he expelled his mother and Don Fernando, and after four wars with his cousin of Castile finally succeeded in maintaining his independence, and even in assuming the title of King.