A woman lay dying after being trampled by the mob on the steps of the Capitol on Jan. 6, and her friend was trying to carry her across the threshold to police officers guarding the building’s west side, prosecutors said. But within seconds, two of those officers would be dragged to the ground themselves and brutally beaten.

One lost his helmet, gas mask, baton and cellphone to the mob, prosecutors said, and was sprayed with a chemical irritant and needed staples to close a gash in his head. Another was dragged over the body of the first officer and then beaten with an American flag as he lay facedown in the crowd, according to court records.

Two months after the insurrection, many of the charges involving attacks against police officers have focused on the Capitol’s West Terrace, a ceremonial doorway that was being prepared for the presidential inauguration of Joe Biden.

“That specific entrance was the site of some of the heaviest violence . . . as the mob of rioters battled with police officers on-and-off from approximately 2:40 p.m. to 5:15 p.m.,” prosecutors wrote Tuesday in a detention memo for a former State Department employee accused of taking part in the mob. “Over a period of about two-and-a-half hours, groups of rioters came in waves and gathered in the archway and tunnel as they attempted to violently breach the police line to gain entrance into the Capitol.”

More than a third of the 40 people charged with assaulting law enforcement officers were allegedly involved in clashes on the West Terrace of the Capitol, according to a review of charging documents and a Washington Post analysis of arrest data.

About half of those accused of attacking police are in jail, while the rest have been released pending trial. The FBI is searching for hundreds more who are suspected of assaulting officers. Prosecutors have said that about 140 U.S. Capitol and D.C. police were assaulted that day.

Federico Klein, a former State Department aide, is the first Trump administration appointee to be implicated in the violence, but others accused of brutality against law enforcement officers include retired police officers, firefighters and National Guard members.

“This was one of the most dangerous areas,” U.S. Magistrate Judge Zia M. Faruqui said in ordering Klein held on Tuesday.

D.C. police officers have said they were determined to hold the rioters back from that path to the Rotunda, not knowing that other entrances already had been breached.

“It was us 30 or 60 officers against, like, thousands and thousands of people that were trying to get in,” Cmdr. Ramey Kyle told The Post in January. “We were going to be the cork in this hole that kept them from entering.”

The officers repeatedly managed to push the rioters out of the tunnel only to be overrun again, Assistant U.S. Attorney Jocelyn Bond said in court Tuesday.

“They ended up spending about 2 1/2 hours that day battling back the mob over and over,” Bond said.

Klein, she said, breached the tunnel early and then called for fresh recruits.

At least five criminal cases involve just two minutes, from 4:27 to 4:29 p.m., when three D.C. officers — identified as B.M., C.M. and A.W. in court papers — were injured. In those same two minutes, just outside the doorway where the officers were trying to hold back the crowd, prosecutors say, Rosanne Boyland “was dying after being trampled by the mob.”

No cause of death has been given by D.C. authorities for Boyland, 34, or the other two people who died after suffering medical emergencies on Jan. 6. Before Boyland collapsed, according to court records, people in the crowd were throwing things at the police and using the officers’ riot shields against them; one had opened a fire extinguisher on the officers. Then they began to grab the officers and drag them into the mob.

After Boyland fell, and her friend was pleading with A.W. and other officers for help, rioters knocked A.W. down in the archway over the entrance to the Capitol. B.M. was then dragged out of the archway over A.W.’s body and into the crowd; C.M. was injured trying to help B.M.

Jeffrey Sabol, a geophysicist from Colorado, is accused of later punching B.M., pulling him down and holding him on the ground with the officer’s baton. Once B.M. was on the ground, Peter Stager, 41, an Arkansas resident, allegedly came up the stairs and began beating him with an American flag, according to the court records.

When C.M. tried to rescue B.M., according to court records, he was stopped by someone wearing clothing marked with the emblem of the Three Percenters, a far-right anti-government group. C.M. tried to push past that rioter with his baton, according to the court records, when conservative activist Michael J. Lopatic Sr., 57, allegedly climbed over the handrail, charged and repeatedly punched the officer in the head. Prosecutors say Lopatic then made his way to B.M. and grabbed the officer’s body camera, which he tossed on his way home to Lancaster, Pa. — destroying important evidence from the attack.

As the officers were being dragged down, prosecutors said, Luke Coffee, 41, an actor from Dallas, used a crutch to push into the line of police guarding the tunnel.

Meanwhile, prosecutors said, Kentucky car dealer Clayton Mullins, 52, and others dragged A.W. into the crowd. Members of the mob kicked him, stomped on him and hit him with poles; they stripped him of his baton, gas mask and cellphone as rioters kicked him. When he managed to make his way back behind the police line in the archway, he realized his head was bleeding.

During a detention hearing last week for Mullins, U.S. District Judge Beryl A. Howell called his behavior “terribly troubling and dangerous” and footage of the scene “frightening.”

But Mullins was released because Howell found that prosecutors had not properly argued that he committed a crime of violence, an issue the government has faced in several cases.

Prosecutors said that some in the crowd tried to protect the police from violence, and through attorneys, several defendants said that that was their intention.

Defense attorney Pat Woodward said in court filings that another assailant pushed an officer into Mullins, who grabbed the officer’s leg to try to help rescue him from the “bedlam.” Woodward said Mullins called out not for more rioters to charge the police, as alleged, but for help saving them.

Sabol’s attorney called the video evidence “ambiguous” and said his client’s voice can be heard in the din, telling people not to attack the police.

Patrick McCaughey, 23, of Connecticut is accused of helping pin D.C. police officer Daniel Hodges in a door with a riot shield; attorney Lindy Urso said his client called for help and tried to put the officer’s gas mask back on.

“Patrick categorically denies that he used or intended to use the plastic shield as a dangerous or deadly weapon, as charged,” Urso added in an email.

Stanley Woodward, who represents Klein, notes that prosecutors describe his client as helping one of the officers who was dragged down the stairs, after blocking another officer from offering aid.

“It was chaos,” Woodward said.

Faruqui gave a hint Tuesday of how judges might view those arguments.

“While there was chaos, it was self-induced,” the judge said. If the video showed Klein “coming to [his] senses and making a better decision,” he said, that just shows he could have done so from the start but made “bad decisions” instead.

Julieanne Himelstein, a former assistant U.S. attorney in Washington, said it’s not uncommon for people charged in a violent assault to claim they were trying to help the victims. It happened when she prosecuted one of the leaders of the 2012 attack on the U.S. compound in Benghazi, Libya, she said.

She said that although it is helpful to prosecutors that “everyone and their mother was tape recording this thing,” they “don’t just have the videotape in a vacuum.”

She added: “You have other means to obtain evidence and to obtain that person’s intent. You have the testimony of the police officer who was assaulted. You have the testimony of an innocent bystander who sees the assault. You have audio, which may show what the person is saying. And then, obviously, potentially you have evidence based on social media.”

This article was produced in partnership with journalism students at the American University School of Communication. Students Ana Álvarez, Aaron Schaffer, Tobi Raji, Maya Smith, Sarah Salem and Sarah Welch, and Post staff writers Peter Hermann, Spencer S. Hsu, Tom Jackman, Emily Davies and Justin Jouvenal contributed to this report.