In the 1140s, the Almoravid dynasty was losing respect and control, so the surrounding areas started forming their own independent small states again. One problem with the Almoravids was difficulty paying their Andalusian military. In March 1145, a local qadi ("judge"), Marwan ibn 'Abd al-'Aziz, tried to manage the increasing mistrust, but the soldiers would not change their attitude about the political leadership and pressured Marwan to take control of the city.
But Marwan still did not have the resources to pay the soldiers, so they replaced him with one pf their own leaders, Ibn 'Iyad. Months later, in January 1146, Ibn 'Iyad called for a son of the ruler of Zaragoza to come and take control of Valencia. This was Sayf al-Dawla ibn Hud, who took the title of Caliph but was killed within days during a battle with Christians. Ibn 'Iyad then asked Muhammad ibn Sa'd ibn Mardanish to take over. Ibn 'Iyad was killed in battle in August 1147.
Christians weren't the only problem for Mardanish. The Almohads were replacing the Almoravids and becoming the dominant force in northwestern Africa, and were crossing the Strait of Gibraltar to Iberia. Mardanish allied himself with Castile to defend against the Almohads, but he died in 1172 and the Almohads had no trouble conquering the Kingdom of Valencia.
The Almohads in Valencia lasted also just a couple generations, weakening so much that the last Almohad ruler, Zayd Abu Zayd, in 1226 agreed to pay tribute to James I of Aragon to avoid war. Abu Zayd's people resented this and rebelled a couple years later. Zayd Abu Zayd and the Almohads abandoned Valencia and a descendant of Mardanish, Zayyan ibn Mardanish, was put in charge.* It was Mardanish who failed to keep Valencia when James I reconquered it after a months-long siege, told about here.
The story of Valencia does not end there. Let's look tomorrow at the later Middle Ages, the Black Death, and that Valencia had a good climate for growing white mulberry.
* Zayd Abu Zayd stayed friendly with James I and even converted to Christianity in 1236, changing his name to Vicent Bellvis. He married a "local girl," Isabella Roldán, and was gifted some localities to rule in Spain.