Near about 950 A.D. king Mularaja of chalukya dynasty had established an independent state in Kathiawar and Gujarat. A Khajuraho inscription indicates that about 950 A.D. king Dhanga of Chandela dynasty had established his authority from Kalinga to Malva and from Kalindi to Gopridi parvat after defeating the Pratihara king. In the course of time Singhraj and Vigrabharaj of chauhana dynasty had made themselves independent in the central Rajuputana. Near about 950 A.D. Chedi king Lakshmanraj deva had defeated the king of Gurjar Pratihara dynasty and established an independent state as well.
Thus when Vijayapala was succeeded by Rajyapala his empire was limited to debt and there were all round difficulties and troubles. The samantas were rising in revolt and were establishing their independent state. Moreover, the Muslims of Gazani were planning to attack India.
Struggle with the Muslims: King Jayapala of the Shahi dynasty had sent an army against sultan Subuktagina of gazani to establish his authority over him. But this army of Jayapala suffered a reverse and Jayapala entered into a treaty with Subuktagina. But soon he broke the treaty and made some generals of Subuktagina as his captives. Being enraged with this Subuktagina again attacked Jayapala. Jayapala invited other Indian kings to help him against the Muslim ruler. Kings of Delhi, Kannauj, Kalinger and Ajmer sent armies and money for the help of Jayapala. But despite this Jayapala was defeated and the sultan captured 200 elephants and looted a lot of other valuable things.
This defeat made Jayapala very sad and entrusting the administration of his kingdom to his son Anandapala, he committed suicide. Near about 1008 A.D. Mahmud again attacked Anandapala. This time again the kings of Delhi, Ajmer, Gwalior, Ujjain etc. helped Anandapala with money and soldiers. This combined army fought bravely against the Muslim invaders and they were on the verge of defeat. But unfortunately at this moment the elephant of Anandapala become out of control and fled away from the battlefield thinking that the senapati had fled away, the soldiers also stopped fighting and put off their arms. Thus this attempt of the Hindus also proved unsuccessful.
After some time Mahmud Gazani decided to attack Kannauj. After crossing Yamuna river he reached Baran. The king of Baran became a convert to Islam along with his 10,000 companions. Mahmud was such encouraged with this victory that he attacked king Kulachandra of Mathura. Though Kulachandra fought with courage and bravery yet he was defeated. He killed his wife and thereafter himself committed suicide. After destroying the beautiful temples of Mathura, Mahmud proceeded towards Kannauj. It is said that during that time Kannauj was the greatest city of India and there were 10,000 temples in the city. There were seven forts for the defense of the city.