Mr Khan's arrest on corruption charges has sparked protests across Pakistan
Eight people have died nationwide in the protests and about 1,000 have been arrested, police say.
The army is being deployed in some areas, and has issued a stern warning after crowds attacked its properties.
Mr Khan's arrest dramatically escalated tensions between Mr Khan and the military at a time of economic crisis.
Conviction would disqualify the former cricket star - prime minister from 2018 to 2022 - from standing for office, possibly for life. Elections are due later this year.
Dramatic footage showed dozens of security officers forcibly removing the 70-year-old from court on Tuesday, then bundling him into a police vehicle.
There is tight security at the police guesthouse where he is being detained, which is also serving as a courtroom.
On Wednesday Mr Khan was indicted on charges that he unlawfully sold state gifts during his premiership, in a case brought by the Election Commission.
He denies the allegations and says he fulfilled all legal requirements.
It was the first of dozens of cases against him in which he has been formally charged.
For months he had avoided arrest, with his supporters at times fighting pitched battles with police to keep him out of custody.
Tuesday's arrest was based on a new warrant for a separate corruption case, connected to the alleged transfer of land for Al-Qadir University, near Islamabad. The judge remanded Mr Khan in custody for eight days in this case.
One of his lawyers, Sher Afzal Marwat, said his client was faring well and relayed a message to supporters not to give up: "You have to stand your ground for Rule of Law," Mr Khan said.
His Pakistan Tehreek-e-Insaf (PTI) party said it would challenge the legality of his arrest in court.
The action by Pakistan's anti-corruption body has led to violent protests across the country.
The government has called the army in to maintain order in several regions of the country, including Khyber Pakhtunkhwa, Punjab, Balochistan, and Islamabad.
In a televised address to the nation, Pakistan's Prime Minister, Shehbaz Sharif, warned that violent protests would not be tolerated.
"The perpetrators who take the law into their own hands will be dealt with with an iron hand," he said.
Extraordinary scenes on Tuesday evening showed Mr Khan's supporters ransacking the corps commander's residence in Lahore, smashing chandeliers and making away with peacocks - among other things - which they said were bought with "citizen's money".
Pakistan's army described 9 May as a "dark day" and warned protesters of an "extreme reaction" if properties of the state were attacked again.
Imran Khan at his residence in Lahore in March
Police in Islamabad used shipping containers to try to block routes to the compound where Imran Khan was appearing before a judge.
The BBC witnessed clashes between protesters and the police in the middle of one of Islamabad's main motorways.
Protesters began gathering after midday, some carrying with them PTI flags or wearing Imran Khan face masks.
Canisters of tear gas were fired into the crowd soon after they began to gather. The protesters attempted to hit the metal casings away using their sticks. There were no arrests during the 90 minutes the BBC were present.
Police use tear gas shells against supporters of Imran Khan
"We came to do a peaceful protest, but these police are shelling us," one man, who was holding stones and a stick and wearing a surgical mask, told the BBC.
"Until our death we will continue this protest or until they free Imran. Otherwise we will shut the whole country."
Mr Khan was ousted last April, less than four years into his term as prime minister.
In November, he was shot in the leg while campaigning among crowds in the city of Wazirabad. He has accused a senior intelligence official of carrying out the attack - an accusation strongly denied by the military. A day before his arrest, the military had warned Mr Khan against repeating the allegation.
Mr Khan's party says he faces more than 100 court cases, which he says are politically motivated.
His supporters argue that the current government wants to bar him from contesting general elections due in October.
Dr Shireen Mazari, the former Minister for Human Rights in Mr Khan's PTI government, told the BBC that the way Mr Khan had been detained amounted to state abduction.
"We don't expect even the military to abuse the sanctity of the court in this way," she said, adding that people in Pakistan were "seething with anger" at the way he had been treated, as well as wider economic problems.
However, Islamabad's High Court declared the arrest legal.
Policemen stand guard along a roadside in Karachi
"Mr Imran Khan will face the law, if innocent, [he] can contest the election. But if found guilty of corruption, he will have to face the consequence of that," Minister of Planning Ahsan Iqbal told a press conference on Wednesday.
Police have arrested supporters of Mr Khan's party, including Asad Umar, its secretary-general.
Mobile internet services remain heavily restricted across the country. Pakistan's telecommunication authorities said they had suspended services on instructions from the interior ministry.
Schools also remain closed, some highways have been blocked and there is little traffic on roads in major cities.
Many analysts believe Mr Khan's election win in 2018 happened with the help of the military. But amid a growing economic crisis, observers say he fell out of favour with the powerful military, the crucial behind-the-scenes player in nuclear-armed Pakistan.
Since being in opposition, he has become one of the military's most vocal critics.
-- Courtesy of BBC News