In Pakistan’s turbulent politics, it has long been held that Allah, the army and America hold sway over who wields power.

Supporters of Imran Khan, the imprisoned former prime minister, are now pinning their hopes on getting him freed — however fanciful — on the wild card among the three: the incoming administration of Donald J. Trump.

Mr. Trump has said nothing publicly to indicate that he plans to intervene in Mr. Khan’s case. Once he is sworn in as president on Monday, Pakistan is unlikely to rank high among Mr. Trump’s foreign policy priorities.

But a series of posts on social media by one of Mr. Trump’s close allies has inspired almost messianic certainty among Mr. Khan’s followers that the once and future American president will help secure his freedom.

The Trump ally, Richard Grenell, has repeatedly demanded Mr. Khan’s release in messages on X. Mr. Grenell, who was ambassador to Germany and acting director of national intelligence in the first Trump administration, was named last month by Mr. Trump as his “envoy for special missions.”

One of Mr. Grenell’s posts about Mr. Khan, written two days after his appointment, garnered more than 12 million views. In another December message on X that he later deleted, Mr. Grenell equated Mr. Trump with Mr. Khan, another celebrity-turned-politician.

“Watch Pakistan,” he wrote. “Their Trump-like leader is in prison on phony charges, and the people have been inspired by the US Red Wave. Stop the political prosecutions around the world!”

Another fierce Trump loyalist, Matt Gaetz, the ex-congressman from Florida, echoed Mr. Grenell with a call on X: “Free Imran Khan!”

It is unclear why Mr. Grenell, who did not immediately respond to a request for comment, has taken up Mr. Khan’s cause.

But members of the Pakistani diaspora have undertaken a vigorous lobbying campaign in the United States as Mr. Khan’s party, Pakistan Tehreek-e-Insaf, or P.T.I., has been battered at home by arrests, crackdowns and censorship.

Mr. Khan — who was once backed by the powerful military but later lost its support — has been jailed since 2023 on a variety of charges. He says the charges are politically motivated. On Friday, a court sentenced him to another prison term, for corruption, along with his wife, Bushra Bibi.

To Mr. Khan’s followers, the proclamations of support from Mr. Trump’s camp have felt like lifelines. “At last, our message is breaking through,” said Atif Khan, a Houston-based official in Mr. Khan’s party.

Hope has spread like wildfire in teeming WhatsApp groups and in living rooms where Mr. Khan’s supporters gather. Each social media post from a Trump ally has been dissected, celebrated and shared as proof that change is imminent.

Mr. Khan’s fervent followers draw parallels between him and Mr. Trump, casting them as outsiders besieged by entrenched elites. Both men have leaned heavily on social media to bypass traditional power structures.

At Raja Bazaar, a crowded marketplace in the city of Rawalpindi that often mirrors the national political mood, Mohammad Sarwar interrupted his search for bargains to voice a sentiment common among Mr. Khan’s followers.

“Trump will help free Imran Khan,” said Mr. Sarwar, 43, invoking the president-elect’s name as though it were an incantation.

Courting American intervention is a striking shift for P.T.I., which has long branded itself as critical of U.S. policies.

Mr. Khan, a former cricket superstar, accused the United States of orchestrating his ouster as prime minister in 2022. But his supporters now frame their struggle as one aligned with American values, saying they are fighting for democratic ideals and human rights.

In the past, Mr. Trump has spoken harshly of Pakistan. He accused its leaders of “lies and deceit” as he froze $1.3 billion in security aid in early 2018. His administration also spearheaded efforts that year to blacklist Pakistan at the Financial Action Task Force, a global watchdog that combats terrorism and money laundering. Those moves are still sore points in Pakistan, officials say.

Mr. Khan became prime minister later in 2018. Mr. Trump invited him for a meeting at the White House in July 2019. The next January in Davos, Switzerland, he called Mr. Khan “a very good friend of mine.”

Officials in Pakistan’s governing coalition have dismissed P.T.I.’s expectations for the incoming Trump administration as fantasy.

“P.T.I.’s hopes are unrealistic,” said Khurram Dastgir-Khan, a former defense and foreign minister who belongs to the ruling Pakistan Muslim League-Nawaz party. “The Trump administration, even if inclined to pressure Pakistan, would likely prioritize financial leverage, not the release or return of Khan to power.”

Pakistan’s military establishment, the invisible hand behind the country’s politics, has shown no signs of softening toward Mr. Khan.

Faisal Vawda, a senator with close links to the military, said he did not expect the Trump administration to make great efforts to aid Mr. Khan, noting that it had been several weeks since Mr. Grenell last called for his release.

“I don’t see any good news coming from the Trump administration for P.T.I.,” Mr. Vawda said. While P.T.I. has been working through lobbyists in the United States, he said, “similarly, the Pakistani establishment has done its own diplomacy, and this explains why the tweets have stopped.”

“I see Trump working with Pakistan, the army and the government,” Mr. Vawda said.