The Moors were a group of Arabic-speaking, Muslim invaders who conquered almost all of the Iberian peninsula between the years of 711 and 718 CE. The history of Spain and Portugal was profoundly altered by the period of occupation, which wasn't formally ended until 1492, when the final Moorish emirate, the city of Granada in Andalucía (the south of modern Spain) fell.
718 was the year of the first defeat of the Moors by Iberia's Christian population. Pelayo, a Visigoth and a local king in what is now Asturias, led his troops to victory in the Battle of Covadonga. This began the period known as the Reconquista, or "Reconquest". During this period, the Christian population slowly began to take back territory, starting in the tiny sliver of Christian Iberia remaining in Asturias and Cantabria, along Spain's mountainous northern coast. The Reconquista lasted for over 700 years, even though the Moors conquered it in only seven.
The importance of this period lies in the creation of a unified Spanish culture. After the Roman Empire collapsed in the 400s, Spain reverted to a primitive culture. Its inhabitants, the Celtiberians, were the result of the combination of Spain's original inhabitants, the Iberians, and a Celtic population that entered later. They retained Vulgar Latin as their language, and Christianity as their religion, but accomplished few of the achievements of the Romans. Thus, Spain was quickly invaded by various Germanic tribes, including the Visigoths. These Teutonic groups existed fairly peacefully with the Celtiberians, and took their religion and language. But very little cultural identity existed in this time.
During the Reconquista, however, the small Christian kingdoms that formed in the reconquered territory began to join into larger states: Asturias, Leon, Castile, and the states along the Spanish March: Aragon, Navarre, and Catalonia. The newly-liberated Spanish population evolved new languages: Portuguese, Spanish, and Catalan, among others. And a modern, feudal, European culture (though distinctly affected by Arabic influences) developed.
At the same time, Spain gained a great deal in scientific and mathematical knowledge from the Arabs. Arabic doctors and scientists were far more advanced at this time than their European counterparts, and much of their knowledge passed to Europe through Spain.
Most of the reconquest was conquered by the Spanish kingdom of Castile, which became independent in 1035 and in 1230 became a major power when Leon was annexed by Ferdinand III, Castile's ruler. Castile's capital was in Toledo, very near to Spain's modern capital Madrid. Soon after, the major cities of Cordoba (1236) and Sevilla (1248) were reconquered. The loss of the largest and most important cities in Moorish Spain (Cordoba had been the capital of Arab Spain) was a major blow to the Muslims. By the end of the century, only Granada remained, and it retained power by paying tribute to Castile's monarchs.
During the 15th century, Spain became a unified kingdom, and Granada fell to the assault of Ferdinand and Isabella's armies in 1492. Later that year, all of the Muslim inhabitants of Spain were expelled, having previously lived more-or-less freely among Spain's Christian inhabitants - a privilege which the Moors freely granted Christians and Jews. But Spain's king and queen were fanatical Catholics - they were even known as "los Reyes Católicos" - "the Catholic Kings."
The Moorish period lasted 700 years, and their presence led to the forging of the Spanish culture and identity, and although Spain hasn't been a center of Muslim learning and culture for over 500 years, the presence of Muslim (and Mudéjar) architecture to this day attests to the profound mark left upon Spain.