The Almoravid dynasty took control of the city from 1094 to 1141. The instability of the Almoravid kingdom led to the Second Taifa Period. The Wazirids were independent from the Almoravids and controlled the city until 1147 when the Kingdom of Portugal besieged the city from July to October, which marked the end of Muslim control in Central Portugal.