ISLAMABAD — Pakistan’s story has long been dominated by a power struggle between its two main characters: the country’s mighty military and its weak civilian government. Now, as if the story weren’t sordid enough, the rise of Pakistan’s judiciary has introduced a third character, one that analysts worry could be highly unpredictable.

Its power was on display this week when the country's Supreme Court formally charged Prime Minister Yousaf Raza Gilani with contempt of court, a move that could eventually lead to the leader’s dismissal.

And then, not to appear unfair, the court took on the military as well. For the first time in the country’s history, Pakistan's Supreme Court forced the Inter-Services Intelligence agency (ISI), the country’s formidable spy organization, to bring before the court seven prisoners it is accused of detaining illegally.

More from GlobalPost: How a mom is taking on Pakistan's spy agency

Proponents and critics raise points from both ends regarding the surge of the judiciary's power.

A stronger judiciary, one that is willing to hold the government and the military accountable, could be good for Pakistan, observers said. But many of them remain wary, unsure whether the court’s intentions are honorable or dubious.

Gilani, flanked by ministers, governors, coalition partners and other supporters, appeared surprisingly calm during his visit to the court on Monday.

Outside the imposing courthouse, helicopters hovered and riot police guarded the entrance.

Gilani is charged with contempt for not writing a letter to the Swiss authorities asking them to reopen corruption cases against President Asif Ali Zardari, who as head of the ruling political party, is also his boss. Gilani pleaded not guilty, arguing that Zardari enjos immunity as president.

Constitutional experts say that if convicted, Gilani could appeal. And as a last resort, the president could pardon him. Gilani said in a recent interview with Al Jazeera however that, if convicted, he would automatically lose his parliamentary seat and thereby his post as prime minister.

It would be a major shake-up for the civilian government, which has so far survived multiple confrontations with the military and the judiciary and as a result, and against all odds, has become the longest-serving civilian administration since the 1970s.

More from GlobalPost: Pakistan's civilian government on trial

The Supreme Court also heard the case of eleven prisoners in custody of ISI – four of whom died in mysterious circumstances. The court had asked the shadowy spy agency to produce the seven remaining prisoners before the court twice last week, but they never showed.

The court persisted, and officials at ISI finally relented on Monday. The prisoners looked frail, with dark circles around their eyes. A number of them needed someone’s support to walk, and one held a catheter.

The chief justice ordered hospital treatment for all seven. The next hearing is scheduled for March 1 and will seek to clarify, among other things, how the four died and whether or not any of the prisoners received a fair trial.

The seven men had an emotional reunion with family members who they had seen only a few times since they were picked up by the spy agency almost five years ago.

“Prove our crime! Prove our crime!” screamed Mohammad Shafiq, one of the detained prisoners, as his brother held him. Asked whether he thought justice would be served, he shook his head and tears ran down his face. “Why not?”

The two cases seem to indicate that the country’s judiciary is asserting its independence and, perhaps, a new found bravura that began to develop during the rule of former President Pervez Musharraf.

Pakistani judges had in the past largely been lackeys of the government and the military. But when Musharraf suspended Chief Justice Iftikhar Mohammad Chaudhry for “abuse of office” in 2007, a march toward greater independence began.

More from GlobalPost: Is Pakistan's military conspiring to take over?

Musharraf’s move was widely seen as an attempt to preempt a court decision that would have invalidated his reelection. Thousands of emotional protesters, led by prominent lawyers, took to the streets. Never before had Pakistan’s judiciary enjoyed such popular support.

In 2008, after the election of the current government and a year of prodding, Chaudhry was finally reinstated.

Since then, Pakistan’s judiciary has become more aggressive, drawing its power in part from widespread dissatisfaction with the performance of the civilian government and from a press that is asking more questions than it did a decade ago.

Although the government has been tripped up by its clashes with the military and the courts, the public hasn't forgiven it for presiding over a period of economy disaster. Double-digit inflation has plagued Pakistan for the greater part of the government’s tenure, and foreign direct investment has dropped significantly in the face of security concerns. A severe energy crisis has also hampered economic growth, which is already not half of what it needs to be to sustain the yearly influx of new workers.

The media has also played an important role in the the military-judiciary-government power equation, said Ali Dayan Hassan, director of Human Rights Watch in Pakistan. In the last 10 years, it has presented more alternative views than Pakistan has ever seen before, but it still faces taboos.

“You have a situation where there are three actors engaging in a political turf-war and the media is only really free to hold one of them in account. It is not that some media do not try and do it, but if the prime minister can be summoned for contempt of court, so can any journalist,” he said. Many journalists in Pakistan censor themselves to protect against possible retaliation from the military, the courts or the government.

The courts, it seems, much like the military, appear to be interested in more than the fair application of the rule of law. Opponents say it has ventured too far into the political realm, which could ultimately hurt the country’s efforts at democratic reform.

“The Supreme Court has literally taken over executive functions. Even if we take the chief justice’s intentions positively, it is still dangerous. It has to keep status quo. It is not meant to be a revolutionary institution,” said Fawad Hussain Chaudhry, a lawyer from Lahore.

The Supreme Court has intervened on political decisions repeatedly since its chief was reinstated. It nullified the carbon tax a week after the government introduced it, for instance. It also suspended the privatization of state companies and even, at one point, set sugar prices, a move many saw as an obvious over-stepping of its responsibilities.

Average Pakistanis have also accused the court of targeting the government unfairly, leading to conspiracy theories that the court is being supported by the military, which has at times acted openly hostile toward the current civilian leadership.

A wave of public criticism may have persuaded the Supreme Court to pursue the case of the eleven prisoners, as well as another, 15-year old case that accuses the ISI of using taxpayer’s money to support political opposition parties in the 1990s.

For others, the Supreme Court is a modern judicial Robin Hood. Analysts say it has recovered tens of billions of rupees (comparable to hundreds of millions of US dollars) by pursuing corruption cases.

“Imagine, had there been no judicial activism, Pakistan would have been in further abyss,” said Umar Cheema, an investigative reporter for The News, a daily newspaper based in Islamabad.

The rise of the judiciary comes at a time when the original battle, the one between the government and the military, is beginning to change. Lacking popular support, the military is no longer able launch an overt take-over, as it had before — three times in the last 64 years.

Rashid Rehman, editor of the Daily Times, another Pakistani newspaper, said that opposition political parties are no longer willing to back a coup, which has forced the military to devise other ways to vie for power.

A battle between the two erupted earlier this year with the surfacing of an unsigned memo, allegedly written by Pakistan’s government, that asked for Washington’s help in preventing a military take-over.

The courts, of all institutions, will likely be forced to resolve the fight, which has been dubbed Memogate by the media. A judicial commission is set to hear the main witness, the Pakistani-American Mansoor Ijaz, who first revealed the existence of the memo last year, on Feb. 22, via a video link from the Pakistani embassy in London.

The turf-war between the three groups has two possible outcomes, said Hassan, one very good and one very bad.

“Either this process will lead to all stakeholders to understand the limits of their domains, or it will lead to confrontation and a break down of constitutional order,” he said.