Answer
Mehmed IV's reign ended in 1687 when he was overthrown by his own soldiers. This was largely due to his failed military campaigns, particularly the disastrous defeat at the Battle of Vienna in 1683, which marked the beginning of the decline of the Ottoman Empire. Mehmed IV was seen as responsible for these failures, leading to widespread discontent and eventually his overthrow.