Towards the close of the tenth century as the Ommeyad caliphate grew weaker, the Christian princes of Visigothic descent, who dwelt in the mountains of the Asturias, began to grow more bold in their attacks on the declining power; and in 997 Bermudo II., king of Gallicia, won back the first portion of modern Portugal from the Moors by seizing Oporto and occupying the province now known as the Entre Minho e Douro. At the beginning of the eleventh century, the great Moorish caliphate finally broke up, and independent Mohammedan em[=i]rs established themselves in every large city, against whom the Christian princes waged incessant and successful wars. In these wars the Celtic inhabitants of the peninsula took but little part; the Moorish armies consisted of Mohammedans, the descendants of the fierce soldiers of Abder-Rahm[=a]n and a few Mosarabs, while the Christian armies consisted only of the feudal chivalry of the northern mountains.
In each army different customs prevailed; the strength of the Moors lay in their perfect military discipline and absolute obedience to their generals; that of the Christians in the new impulse to valour given to each individual knight by the laws of chivalry. On neither side was personal ambition without an incentive; Moorish generals hoped to become em[=i]rs, Christian knights, feudal counts. The finest soldiers of both armies were foreigners to the peninsula, being on the one side Africans, on the other either of Gothic descent or else the flower of the chivalry of northern Europe, which went to win its spurs in the wars against the unbelievers, and especially admired and followed the Cid, Rodrigo Diaz de Bivar. Between these two contending bands of warriors the unfortunate Celtic inhabitants of the middle zone of the peninsula were crushed; those of the mountains of the north were by feudal custom obliged to take up arms to follow their lords, and after a century or two those of the centre by the force of necessity became warriors also, and proceeded to drive the Moors back to Africa.
The eleventh century was at first marked by great Christian successes, especially in the west of the peninsula. In 1055 Ferdinand "the Great," king of Leon, Castile, and Gallicia, invaded the Beira; in 1057 he took Lamego and Viseu; and in 1064 Coimbra, where he died in the following year. He arranged for the government of his conquests in the only way possible under the feudal system, by forming them into a county, extending to the Mondego, with Coimbra as its capital. The first count of Coimbra was Sesnando, a recreant Arab vizir, who had advised Ferdinand to invade his district and had assisted in its easy conquest. He had married a Christian, and was ready to defend his new religion and the dominions he held under the Christian king with all the more vigour from the knowledge that the Moorish em[=i]rs and w[=a]lis to the south regarded him as an apostate. But though Sesnando's county of Coimbra was the great frontier county of Gallicia, and the most important conquest of Ferdinand "the Great," it was not thence that the kingdom which was to develop out of his dominions was to take its name. Among the counties of Gallicia was one called the "comitatus Portucalensis," because it contained within its boundaries the famous city at the mouth of the Douro, known in Roman and Greek times as the Portus Cale, and in modern days as Oporto, or "The Port." This county of Oporto or Portugal was the one destined to give its name to the future kingdom, and was held at the time of Ferdinand's death by Nuno Mendes, the founder of one of the most famous families in Portuguese history.