Pervez Musharraf, Pakistan’s longtime military leader, spent Friday night in comfortable police quarters before appearing in an anti-terrorism court Saturday to formally face charges centering on his 2007 suspension of the constitution and mass firing of senior judges.

The retired general, who ruled Pakistan for nine years, has unsuccessfully sought bail in a showdown with an increasingly assertive judiciary determined to bring him to account for his autocratic actions before relinquishing power under pressure in 2008.

If convicted, he would be the first former army chief to go to prison in Pakistan’s 65-year history, which includes long stretches of military rule and coups such as the one Musharraf launched to gain power in 1999. That prospect has raised fears of a backlash by a powerful military leadership that considers Musharraf one of its own, even if he is no longer well liked among the brass.

In an uneventful hearing, the anti-terrorism court continued the case — which essentially portrays Musharraf as an enemy of the state — until May 4. He left under heavy security, offering the occasional salute, to spend the next two weeks in custody.

There was an element of irony to his appearance in that court: Musharraf famously allied Pakistan with the United States in its counterterrorism operations and war against al-Qaeda and the Taliban after the Sept. 11, 2001, attacks.

Musharraf, 69, calls the charges against him baseless and politically motivated, but he began bowing to the law Friday after dramatically fleeing a courthouse Thursday to avoid detention.

It was unclear whether he will spend the next two weeks under house arrest at his villa on the capital’s outskirts, as his lawyers are seeking, or have to remain at an officers’ club attached to central police headquarters in the capital.

While some political analysts have predicted a destabilizing battle between the courts and the army if the retired four-star general is put on trial, others hope for a clean and quick resolution — preferably one that avoids further humiliating Musharraf, whose return to Pakistan last month to run for prime minister has proved disastrous.

A smooth exit would ease tensions in the tumultuous nation as it heads into elections on May 11 that will bring an unprecedented handoff of power between elected governments.

On Friday, Pakistan’s Senate, sitting in a limited session, passed a resolution demanding that Musharraf be tried for abrogating the constitution. All major contenders for prime minister in the upcoming elections have piled on, urging punishment.