The Rahma-Wahhabi alliance did not last long. In 1812, Egyptian troops drove the Wahhabis from the Hijaz, and the Omani ruler Said bin Sultan al-Said took the opportunity to expel the Wahhabis from Qatar. Rahma bin Jabir consequently switched allegiance to Oman. The Khalifa family and the Wahhabis occupied Khor (Khawr) Hassan in response, forcing Rahma to settle on the Persian coast. From Bushehr on the Persian coast he continued to attack Bahraini ships. In 1826, old and blind and realizing his ultimate defeat, Rahma blew himself and his eight-year-old son up during a last desperate sea battle with his arch-enemies.
Both the Wahhabis and the Omanis proved unable to control Qatar. Instead, the peninsula became a battleground for political rivalry within the Bahraini Khalifa family. By tactically switching allegiance between feuding Al Khalifa members, Isa bin Turayf of the Qatari tribe of Al Bin Ali challenged Bahraini influence from his base in Doha. In 1847, Bin Turayf was killed in battle. The Al Bin Ali were driven from Doha by the ruler of Bahrain, Mohammed bin Khalifa. Mohammed then sent his brother Ali to Doha as governor, in an attempt to pacify the Qatar peninsula.
Ali’s first tenure was short-lived. He fled from Doha in 1850 when Saudi-Wahhabi forces once again invaded Qatar. After Ali’s forced departure, the tribes of Qatar struck an alliance with the conquering Saudis. This gave the Saudi leader Faysal bin Turki the opportunity to launch an invasion of Bahrain from Qatar. It was only the intervention of the British (whose navy had by then established a ‘Pax Britannica’ in the Gulf waters in order to secure British trade routes to India) that prevented an attack. A peace treaty between the belligerents was concluded and Ali returned to Doha. But the Saudi threat continued, and in 1861 an agreement was reached between Britain and the Khalifa family in which the former pledged to protect Bahrain and its ‘dependencies’ (i.e. Qatar) from attack by sea, in exchange for a Bahraini pledge to abstain from maritime warfare.