An Afghan invasion of Iran at the beginning of the 18th century resulted in the near collapse of the Safavid state. In the resultant power vacuum, Oman invaded Bahrain in 1717, ending over a hundred years of Persian hegemony. The Omani invasion began a period of political instability and a quick succession of outside rulers took power with consequent destruction. According to a contemporary account by theologian, Sheikh Yusuf Al Bahrani, in an unsuccessful attempt by the Persians and their Bedouin allies to take back Bahrain from the Kharijite Omanis, much of the country was burnt to the ground. Bahrain was eventually sold back to the Persians by the Omanis, but the weakness of the Safavid empire saw Huwala tribes seize control.