After the death of Koprulu Ahmed Pasha, Merzifonlu Kara Mustafa Pasha held the viziership in November 5, 1676. Hungary had revolted against Austria and wanted Ottoman authority again. Mustafa Pasha declared Emeric Thokely king to the central Hungry.

After, Emeric Thokely took the leadership of the Hungarians, he rebelled against the King of Austria Leopold I. Thokely asked for an Ottoman assistance and Mustafa Pasha had besieged Vienna in July 14, 1683.

The siege took 60 days. Mustafa Pasha was waiting for a fatal attack but the Pope sent the King of Poland to Vienna to defend the city.>

The Austrian and the Polish armies defeated the Ottoman army. The Ottomans withdrew through Belgrade. With the withdrawal of the Ottomans, Austrians entered Hungary, and invaded Vishgrad, Uyvar and Budapest.

This was the second siege of Vienna and the Ottomans failed to capture the city for the second time.

After, this defeat Sultan Mehmet IV was dethroned with the decision of council. Prince Suleyman replaced him in November 8, 1687.