ISLAMABAD, Pakistan — One month ago, it looked as if Pakistan’s orderly capital was about to go up in flames.

Thousands of protesters were marching toward the city from all directions, spurred by charismatic opposition leader Imran Khan and his crusade against alleged financial misdeeds by Prime Minister Nawaz Sharif. The government, determined to stop them, blocked the roads with cargo containers and concrete slabs, and troops were ready with tear gas and rubber bullets.

Today, the threat of violent confrontation in the streets — averted at the last minute when the Supreme Court intervened — has been replaced by a drawn-out courtroom duel between two political camps. The country has been riveted by the clash of titans, with its blizzards of documents, grandiloquent speeches and competing versions of convoluted ­financial transactions that took place years ago in London, the Middle East and the British Virgin Islands.

The latest chapter opened Wednesday at a brief but dramatic hearing before a high court panel. Lawyers for Khan accused the prime minister of “lying to the nation” when he declared publicly that he had not hidden any assets abroad or evaded taxes. Aides to Sharif, speaking after the hearing, retorted that “Mr. Khan has always lied to the nation” and that his claims were based on “newspaper clippings” rather than evidence. The hearing was adjourned until next week.

The case, which centers on the ownership of four apartments long occupied by members of the Sharif family in a posh section of London, does not seem likely to lead to the prime minister’s removal or resignation, although he has pledged several times to step down if found guilty. Whatever the outcome, though, it seems likely to have a far-reaching impact on Pakistani politics.

Charges of corruption have long swirled around the ruling civilian elite — dominated for decades by the rival Sharif and Bhutto families — as well as the powerful military establishment and its allies in business circles and the civil bureaucracy. Now, with the rise of social media and an emboldened nontraditional opposition, these practices are coming under unprecedented public pressure.

“I think this is a defining moment for Pakistan and democracy,” Khan, 64, a former cricket star who leads the Pakistan Movement for Justice, said in an interview at his hillside suburban home. “All those who benefit from corruption want to preserve the status quo, but the young generation wants change and accountability.”

After the court case concludes, he said, “we hope history will be made.”

Aides to Sharif and leaders of his party, the Pakistan Muslim League-N, paint a darker picture of Khan, his motives and his base of support. They say the true source of corruption is the military and bureaucratic establishment, which fears Sharif’s electoral popularity, and they suggest these groups are quietly backing Khan’s campaign. Sharif, 66, was ousted by a military coup in 1999 and exiled for a decade, but then elected to his third stint as prime minister in 2013.

The current controversy erupted in April when Sharif was mentioned in the Panama Papers. Leaked to a watchdog group from an offshore law firm, they listed hundreds of wealthy individuals and several foreign leaders as ­having financial assets hidden abroad. Sharif’s advocates, however, say that during the military regime of Gen. Pervez Musharraf, more than 50 cases were brought against Sharif for alleged financial wrongdoing, including the London property issue, and all were dismissed or exonerated him.

“This is all total falsification and fabrications of claims of wrongdoing. There is nothing there,” said Daniyal Aziz, a legislator from Sharif’s party and one of his chief public spokesmen, noting that Sharif was later removed from the website that published the Panama Papers.

Khan, who led protests in 2014 claiming that Sharif’s election was rigged, seized on the new scandal in the summer, drawing larger and more feverish crowds, and finally threatened to “lock down” the capital on Nov. 2 if Sharif did not resign or present himself to the court. On the eve of the looming confrontation, the Supreme Court suddenly announced that it would hold a hearing on the charges against Sharif. Khan canceled the protest and renamed it a day of celebration.

Since then, the court case has produced a wealth of fascinating developments, especially insights into the complex world of offshore financial dealings. The key questions are how the Sharif family acquired and sold the apartments, where it got the money, why it was not reported, what role Sharif’s adult children had in the transactions and whether offshore companies were used to hide the money trail.

Sharif and his lawyers, while denying that any laws were broken, have given several explanations as to how the property came into the family, some stemming from business deals related to steel mills owned by his late father.

Two weeks ago, an exotic new wrinkle was added when a Qatari prince sent a letter to the court stating that his family had transferred the apartments to Sharif’s children at no cost as part of an old business settlement with his father.

The justices, unimpressed, noted that a letter was not legal proof. Expressing repeated determination to stay away from politics, they have asked sharp questions of both sides, demanded explanations of apparent inconsistencies and expressed wry exasperation at the torrent of documents submitted, comparing some to fairy tales and pastry wrappings.

Khan, a heroic figure to his legions of supporters, has also come under fire for allegedly misusing charitable contributions for campaign purposes and, ironically, for using offshore companies to buy and sell a luxury apartment in London. He has been dismissed by some as a dilettante, an opportunist and a rebel without a plan.

But the far more serious charge, which Khan denies, is the suggestion by some Sharif supporters and media figures that he is in cahoots with the military establishment, or has let himself become their “puppet,” in a quest to become prime minister, and that he even risked his followers’ safety by goading them toward the capital “lockdown” to provoke a coup.

“Nawaz sees demons everywhere. Everything we have done is constitutional and within our rights in a democracy,” Khan said in the interview. “If the army came in, we would be the losers. Why would we want that?” He also praised the country’s outgoing army chief, Gen. Raheel Sharif, for staying out of politics and retiring this week.

There is no doubt, though, that Khan’s popular challenge to the Sharif government, leveraged by the Panama Papers scandal and joined by several other political and religious groups, has rocked Pakistan’s establishment more than anything in years.

Whatever comes of the legal battle, the energized outsider movement that started as a one-man show is now a force to be reckoned with in a country where grass-roots politics have always been managed from the top down.