In the next period Tlemcen became the capital of the (Ziyyanid) kingdom of Tlemcen (1236 - 1554) and was ruled for centuries by successive Abdalwadid sultans. Its flag was a blue crescent pointing upwards on a white field. The city was temporarily captured by the Marinid sultan, Abu al-Hasan Ali (1337-48). The kingdom of Tlemcen had grown rapidly after its foundations in 1236 and eventually controlled most of the Atlas Mountains to Tunisia at its height in the 15th century. When the Spanish took the city of Oran from the kingdom in 1509, continuous pressure from the Berbers prompted the Spanish to attempt a counterattack against the city of Tlemcen (1543), which was deemed by the Papacy to be a crusade. The Spanish failed to take the city in the first attack, although the strategic vulnerability of Tlemcen caused the kingdom's weight to shift toward the safer and more heavily fortified corsair base at Algiers.
The ruler of Tlemcen is reported to have been advised by a Jewish viceroy named Abraham, who, in the time of the Inquisition of Torquemada, opened the gates of Tlemcen to hordes of Jews and Moors fleeing Spain. Abraham is said to have supported them with his own money and with the tolerance of the king of Tlemcen.
In 1553, the kingdom of Tlemcen came under the protection of the Ottoman Empire, which was fighting a naval war against the Spaniards across the Mediterranean, and the Kingdom of Tlemcen became another vassal of the Sultan in Constantinople. Tlemcen and the Algerian provinces gained effective independence in their own affairs in 1671 , although Tlemcen was no longer the seat of government that it once was (transferred to ?Algiers), and its grandeur was much reduced from the days of its great kings. The Spanish were evicted from Oran in 1792, but thirty years later they were replaced by the French, who seized Algiers. A French fleet bombarded Algiers in 1830, at which point the dey capitulated to French colonial rule; a broad coalition of Arabs continued to resist, coordinated loosely at Tlemcen. The great Arab Abd al-Kader, fought with incredible skill and valor, but his defeat in 1844 at Isly ended the dream of a new independent Algeria.
Tlemcen was a vacation spot and retreat for French settlers in Algeria, who found it to be far more temperate than Oran or Algiers. The city adapted and became more cosmopolitan, with a unique outlook on art and culture, and its architecture and urban life evolved to accommodate this new sense. In the independence movements of the mid-twentieth century, it was relatively quiet, reflecting the city's sense of aloofness from the turbulence of Algiers.