Musharraf had recently returned from self-imposed exile expecting to be greeted as a patriotic savior, but now is being held by police and faces charges stemming from his military rule.

ISLAMABAD, Pakistan — Former Pakistani President Pervez Musharraf was arrested and placed in police custody Friday, a day after commandos whisked him away from an Islamabad courthouse where he faces charges of illegally detaining dozens of judges while in power.

Musharraf, who only a few weeks ago presented himself as a patriotic savior returning to his homeland from self-imposed exile, was being held at police headquarters at least until his next court appearance, which was expected within 48 hours. It was not known whether he would be moved back to his Islamabad residence under house arrest or to a jail cell to await trial.

The 69-year-old former military ruler was arrested at his home without incident early Friday and taken before a judicial magistrate who ordered that he continue to be detained.

He was taken to his sprawling farmhouse residence, a heavily guarded compound fortified with guard towers and razor wire atop tall perimeter walls, and held there under house arrest. But later, police removed him from his residence and took him to police headquarters on the southern edge of the city.

Musharraf's arrest followed a dramatic series of events Thursday, when he failed to surrender to police at the Islamabad High Court building after a judge revoked his bail and ordered his arrest. As Musharraf left the courthouse, the commandos assigned to protect him pushed aside local police officers, put him into black sport utility vehicle and took him home.

Lawyers at the courthouse at the time said it was clear that Musharraf was trying to escape arrest, and that his security team had kept one Islamabad police officer from taking him into custody. Musharraf's aides denied that was the case and said he would have surrendered had police tried to arrest him.

Musharraf's arrest centers on his moves in 2007 to purge the country's courts of 60 judges, including Supreme Court Chief Justice Iftikhar Mohammed Chaudhry. He ordered the detention of those judges at their homes and in 2009 was criminally charged in the case.

He also faces two other criminal cases involving charges that he did not provide enough security to prevent the 2007 assassination of former Prime Minister Benazir Bhutto and allegations that he ordered the killing of a Baluch nationalist leader in 2006.

Musharraf, a former general who ruled the country from 1999 to 2008, returned to Pakistan on March 24 after spending four years in self-imposed exile, living mostly in London and Dubai. He had hoped to engineer a political comeback and planned to run in parliamentary elections slated for May 11.

But his dreams of reviving his standing among Pakistanis, and even perhaps regaining a position of leadership, have devolved into a sideshow.

He expected tens of thousands of backers to greet him at the airport in Karachi when he arrived from Dubai, but only 2,000 people showed up. At a court appearance in Karachi on March 29, an angry lawyer threw a shoe at him, a strong insult in the Muslim world because the sole is considered unclean.

Musharraf filed nomination papers in four districts to run for a legislative seat. Under Pakistan's election rules, a candidate can run in multiple districts at the same time and does not have to be a resident of those districts. But in each of those locations, courts barred him from running, citing procedural flaws in his nomination papers as well as his suspension of the country's constitution while he was in power.

"It seems that he had an unrealistic view of his capacity to mold public opinion in Pakistan," said political analyst Hasan Askari Rizvi. "He was living in a world of illusions."

Despite Musharraf's latest setbacks, his lawyer, Ahmad Raza Kasuri, described the former Pakistani leader as being "in high spirits."

"Some people say he may flee the country, but that will never be the case," Kasuri said. "He will stay in Pakistan."

Kasuri also characterized Musharraf's appearance before the magistrate Friday as a voluntary surrender to authorities. As a result, he said, "his image will improve."

Musharraf appeared grim-faced as he neared the judicial magistrate's tiny courtroom, near a noisy bazaar filled with grocery stalls and tea rooms. Once the dictator at the helm of a nuclear-armed nation, he found himself escorted by police down the same narrow walkway that everyday criminals use to appear before the local magistrate.

On his Facebook page Friday, Musharraf vented about his experience. "These allegations are politically motivated, and I will fight them in the trial court, where the truth will eventually prevail," he wrote.