The video clips shared online by supporters of President Trump presented a disturbing tale: Brian McCafferty, an official observer of the vote count in Philadelphia, had been ejected from the Pennsylvania Convention Center for trying to expose the “coup” going on inside.

“I got thrown out because I took video of corrupt people trying to undermine the president,” McCafferty said in a clip.

Republicans including Donald Trump Jr., Rudolph W. Giuliani and Sen. Ted Cruz (Tex.) shared his videos, one of which was removed for violating Twitter’s rules. McCafferty later recounted his experience on Tucker Carlson’s prime-time Fox News show.

Those sharing the clips highlighted that McCafferty was a registered Democrat, suggesting that any observer expressing doubt over the integrity of the count risked being banished.

But despite his party registration, McCafferty, 52, is a Trump supporter who helps his son run a pro-Trump Facebook page that has secured his son appearances on Russian state media and the far-right website Infowars, The Washington Post found. A city spokesman said he was ejected for breaking a rule against filming.

As the tally from mail-in ballots in Philadelphia erased Trump’s early lead in Pennsylvania, the president’s allies combined McCafferty’s on-the-ground agitation with a flurry of litigation and TV appearances by senior advisers in an effort to discredit the count and falsely claim that rigorous observers were being blocked from monitoring it.

Lauren Vidas, an observer from the nonpartisan nonprofit group Protect Our Vote Philly, told The Post that watchers from both sides were allowed inside, and that she saw more than a dozen GOP representatives inside the convention center during multiple shifts in the days after polls closed.

“I personally introduced myself to the Republican City Committee attorney,” said Vidas. “If the rules allowed it, I would have taken a picture of them to put an end to this conspiracy theory nonsense.”

In the downtown hangar, dozens of shift workers — some wearing bright yellow road-safety vests and being paid $18 per hour — stood at long tables patiently processing hundreds of thousands of ballots from the state’s most populous area into counting machines.

Under Pennsylvania election law, each political party and candidate is entitled to have a representative “in the room” to watch ballots being counted. Braced for conspiracy theories, city authorities also live-streamed the count online.

At the city’s federal courthouse on Thursday evening, attorneys for Trump asked a judge to issue an emergency order to stop the count, alleging that all Republican observers had been barred.

Under sharp questioning from Judge Paul S. Diamond, however, they conceded that Trump in fact had “a nonzero number of people in the room,” leaving Diamond audibly exasperated.

“I’m sorry, then what’s your problem?” asked Diamond, who was appointed to the federal bench by President George W. Bush. Denying Trump’s request, Diamond struck a deal for 60 observers from each party to be allowed inside.

At one point on Friday afternoon, 12 Republican observers and five Democrats were watching the count, according to a ballot counter who was working.

Attorneys for Philadelphia had stressed in court that Republicans were already welcome if they complied with the rules, noting that one had been removed for disobeying social distancing protocol aimed at preventing the spread of the coronavirus.

McCafferty said he was escorted out by a security guard for recording video inside the counting area, which a city spokesman told The Post was against regulations. McCafferty confirmed that he was observing for the Republican Party. “I voted for Trump and I believe in Trump,” he said in an interview with The Post on Friday.

David Thornburgh, the president of the Committee of Seventy, a nonpartisan good-government group in Philadelphia, condemned the efforts to undermine the electoral process.

“They’re trying to scare people, and it’s not merited,” said Thornburgh. “I have full faith and confidence that this has played out as it should have, that they’ve followed not just the letter, but the spirit of the law.”

As part of a last-ditch legal campaign spanning several battleground states, Trump’s attorneys complained to Pennsylvania courts that any observers allowed inside the Philadelphia count were being stationed too far from the activity to see what was going on. City officials, the Trump team said, were using an overly literal reading of the law to prevent effective observation.

“Standing at one end of a room the size of a football field, which coincidentally is about the size of the Philadelphia Convention Center, is a lot different than standing at one end of a room the size of an office,” Trump’s campaign said in a legal brief.

One vivid detail caught the attention of the president. “Observers have been kept far away, so far people have been using binoculars to see,” Trump said during remarks at the White House on Thursday evening.

Some Democrats conceded that, on this, the Republicans had a point. Lisa Wershaw, a Democratic observer, confirmed the binocular use and said that all watchers had been positioned approximately 30 feet away from counting machines on Tuesday and Wednesday.

On Thursday morning, Trump’s team won a state court order to move observers within six feet of the count — as close as city officials said was safe amid the pandemic. In her order, Judge Christine Fizzano Cannon stressed that watching at such close quarters required “wearing masks and maintaining social distancing.”

Supervisors ordered a brief pause in counting while officials digested the court’s decision and worked out how to proceed. But the city quickly appealed to the state supreme court and counting soon resumed.

Pam Bondi, the former Florida attorney general and a loyal Trump ally, promptly appeared in front of TV cameras on the convention center steps, claiming that after moving the observers to within six feet, city officials had then removed the counting machines closest to them.

“Our votes are being suppressed,” said Bondi, who was backed by a team of protesters carrying Trump campaign signs. “We are not going to stand for this.” As she spoke, Democratic counterprotesters tried to drown out her remarks with bursts of noise.

Bondi was flanked by Corey Lewandowski, one of Trump’s 2016 campaign managers, who identified an attorney he asserted was obstructing the court order. Within minutes, Trump supporters had dug through the attorney’s social media and discovered that she had been critical of Trump. Lewandowski soon joined them, posting the attorney’s email address and telephone numbers on his Twitter feed.

One ballot counter working at the Philadelphia site said that she and her colleagues had been unnerved by the highly charged atmosphere outside and the glare of the national political spotlight.

“Every single person working here feels intimidated at some level,” said the counter, who spoke on the condition of anonymity because she feared harassment. “There are sheriff’s deputies everywhere.”

The counter said that she and colleagues had felt threatened by one observer, who was dressed in camouflage and a mask that concealed much of his face while he was staring at them. She said the man’s political affiliation was not clear.

Nerves were further frayed when police in the city receive a tip that armed people from out of state may be headed to the convention center. Two men from Virginia were arrested on firearms charges late on Thursday.

On Friday morning, a new batch of counted ballots from Philadelphia pushed Biden into the lead in the state. Trump tweeted that Philadelphia had “a rotten history on election integrity,” attributing the quote to a Fox Business host.

By the afternoon, one observer inside the convention center was unmistakably from the president’s side: Lewandowski, the former campaign chief, had put in a shift alongside his fellow Trump supporters.

Reached by phone, Lewandowski confirmed his presence but claimed there was a strange lack of activity. “I was there for more than an hour, standing six feet away,” he said. “And I didn’t see them count a single vote.”

Karen Heller and Maura Ewing in Philadelphia and Amy Worden in Harrisburg, Pa., contributed to this report.