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.
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.
Read More:
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.