Imran Khan was released after the Pakistan Supreme Court ruled his arrest illegal.
Former Prime Minister will spend the night in a police guesthouse for his own protection, but will still be able to see a small number of family and friends.
His arrest M Khan on Tuesday has sparked violence across the country, which has resulted in at least eight deaths and dozens of injuries.
As a result of the violence, hundreds more people were detained.
Since he was removed as prime minister in a vote of no confidence last year, Mr Khan, 70 years old, has faced multiple corruption charges before Pakistani courts.
Umar Ata Bindial, the Chief Justice of the Supreme Court, has asked Mr Khan for an appeal to be made to his supporters in order to maintain peace as the country is experiencing increasing turmoil.
Cordelia Lynch, Asia Correspondent, analyzes the situation.
Imran Khan can now meet his family, rally his soldiers and decide his next step.
The Supreme Court ruled that his arrest was unlawful after his arrest by paramilitaries in Pakistan.
The case is now before the High Court. Remember that the High Court previously ruled that the arrest was legal.
Everything in Pakistan feels polarised right now. In Pakistan, there’s talk that the military made a deal behind the scenes with Mr Khan.
The government might not be in favor of it. There is the possibility that Mr Khan could be arrested again and a game of legal cat and mouse resurrected.
The judiciary is now taking action. It is facing powerful institutions that are locked in a struggle for power and never far away from another battle.
This whole incident could end up in Mr Khan’s favor if he can calm down his supporters and prevent them from committing violence.
This will only feed into his narrative of being politically persecuted.
The former leader’s supporters were dancing in celebration of his release near the courthouse.
Babar Awan told reporters that the Supreme Court had reversed all legal actions against Imran Khan. He was asked to appear in front of the Islamabad High Court this Friday.
Imran’s journey as a playboy to Prime Minister
Khan arrested in Islamabad
Police clashes with Khan’s Supporters
ARY News reports that Mr Khan, in reference to violent protests in the country, said he “had no idea” what had happened after his arrest.
The former premier also claimed to the court that he was “kidnapped” from Islamabad High Court and “hit with sticks”.
Mr Khan was dragged out of a courtroom where he appeared to face corruption charges in Pakistan’s capital Islamabad on Tuesday.
He denies any wrongdoing.
Violence erupts across Pakistan
Since Tuesday, Pakistani authorities have taken action against his supporters. Hundreds of people were arrested in raids overnight and troops have been deployed throughout the country to combat violence.
Five of the confirmed eight deaths occurred in the province of Khyber Pakhtunkhwa, located to the northwest.
Two more people were killed in Lahore in the east, and a third person in Quetta in the south-west.
In the clashes that took place on the outskirts Islamabad, more than 200 police officers were also injured.
Police said that almost 1,600 supporters of Mr Khan were arrested over night on charges of damaging property and attacking military facilities.
A mob in Lahore set fire to a house belonging to a senior army commander just hours after former Prime Minister was arrested.
On Wednesday and Tuesday, 2,000 supporters of the former cricketer were arrested.