The developments thrust Pakistan into political turmoil and the prospect of unexpected elections.
The National Assembly had earlier appeared set to dismiss Mr Khan as parliamentarians convened to vote on an opposition confidence motion.
Instead, the 69-year-old former World Cup winning cricketer was granted a reprieve when the deputy speaker dismissed the motion as unconstitutional.
Mr Khan moments later said he would ask the president to dissolve the country's national and provincial assemblies and told Pakistanis to prepare for elections. The cabinet was also dissolved.
The prime minister has repeatedly alleged the motion against him is a foreign conspiracy to kick him out because of his determination to forge his own foreign policy.
As parliamentarians prepared to vote on Sunday morning, Mr Khan's Information Minister Fawad Chaudhry asked the deputy speaker to dismiss the motion as “an operation for a regime change by a foreign government".
Qasim Khan Suri replied that "no foreign power shall be allowed to topple an elected government through a conspiracy", and that points raised by the minister were valid.
He dismissed the motion.
Mr Khan then addressed the country to say: “I ask people to prepare for the next elections. Thank God, a conspiracy to topple the government has failed."
The opposition immediately said it would stage a protest sit-in in parliament and challenge the ruling in the Supreme Court.
Shehbaz Sharif, leader of the opposition with the Pakistan Muslim League (PML-N), called it high treason.
“Imran Khan has pushed the country into anarchy. [Khan] and his cohort will not be allowed to go scot-free. There will be consequences for the blatant and brazen violation of the constitution.”
Bilawal Bhutto Zardari, of the Pakistan Peoples Party, said the united opposition was not leaving parliament.
"Our lawyers are on their way to Supreme Court," he said. "We call on all institutions to protect, uphold, defend and implement the constitution of Pakistan.”
Mr Khan had come under increasing pressure in recent weeks as his parliamentary numbers dwindled amid a host of desertions and defections.
He had been widely predicted to lose Sunday's vote after he was abandoned by a coalition partner last week.
His opponents accuse him of economic mismanagement which has led to months of double-digit inflation, while the prime minister also appears to have had a rift with the influential army.
Imran Khan rallies supporters - in pictures
Mr Khan said: “In a democratic society, the democrats go to the people, elections are held and the people decide who they want to rule.”
Farrukh Habib, Minister for Information, said elections would be held within 90 days. Under Pakistan's constitution an interim government, chosen with input from the opposition, should steer the country towards the polls.
Umar Ata Bandial, chief justice of Pakistan, on Sunday said he had taken notice of the developments and a hearing into the constitutional question was due later during the day.
But Khalid Ranjha, a former law minister and judge, told The National that the Supreme Court may have difficulty overturning the ruling to dismiss the no-confidence vote.
“Our constitution's Article 69 says everything which happens within the parliament cannot be questioned by the courts," he said.
“I very much suspect the Supreme Court will say 'don't drag us into this muck. Let the parliament sort it out.'”
The military also denied any involvement in the dramatic political developments.
"[The] Army has nothing to do with the political process," said Maj Gen Babar Iftikhar, the head of the military's public relations wing.
Opposition parliamentarians meanwhile refused to leave the national assembly chamber after the session was adjourned. They held their own sit-in no confidence vote and reported that 195 members voted in favour of the motion.
The opposition had needed a simple majority of 172 votes in Pakistan's 342-seat Parliament to unseat Mr Khan in the confidence vote. A flurry of political desertions and defections in recent weeks had undercut support for the prime minister. More than a dozen of his own party members had defected along with small, but vital coalition partners.