But a string of failures by Mr Khan’s government slowly persuaded the military they had made a mistake.
A weak economy inherited by the PTI has got worse in the past three years and inflation has started to soar.
Such poor management risked rubbing off on the army which had “selected” the prime minister, generals feared.
Mr Khan’s high octane rhetoric against the West and India also appeared at times to dismay the military, who wanted to take a more conciliatory tone.
Then finally the prime minister tried to interfere in military appointments, when he tried to stop Gen Bajwa from removing Mr Khan’s ally as ISI chief.
The suspicion that the prime minister was trying to manipulate the military line of succession and would one day try to manoeuvre his own man into the top job was too much.
Asfandyar Mir, of the United States Institute for Peace, said: “The dispute over the appointment was the straw that broke the camel’s back, it was not the main fight between the two.”
Suddenly, where Mr Khan might once have relied on military help to keep opposition parties on the back foot, or stop his own parliamentarians defecting, the generals decided to take a step back.
As the political wind changed, the opposition parties led by shrewd political dynasts, quickly circled the prime ministers’ slim parliamentary majority.
Mr Khan quickly fell to a no-confidence vote and Shehbaz Sharif, brother of Nawaz Sharif, has been elected the new prime minister.
The arrest of PTI activists and the rebuttal of Mr Khan’s conspiracy theories have been seen as a warning from the military for him to cool the political temperature of his followers.
However, huge rallies in Karachi and Peshawar in recent days have now shown that Mr Khan remains a potent political force.