When two gunmen forced their way into the 52-year-old man’s D.C. apartment last week, one demanded money and tried to hit him. But the attacker swung wildly, and in the moments that followed the would-be victim managed to grab his assailant’s gun.

“He didn’t have control,” the man said Monday. “I snatched it right out of his hand.”

The second gunman advanced, raising his gun as the first assailant, now unarmed, urged him to “Shoot that [expletive].” But the apartment’s occupant fired first, hitting Joel Johnson in the head, felling one attacker with the gun he took from the other.

The account of the Wednesday-night home invasion that ended with one attacker dead comes from newly filed court documents and a telephone interview with the man who was accosted inside his third-floor apartment on First Street SE. It portrays a struggle far more violent than authorities described last week.

With Johnson lying dead on the living-room floor, the second man raced into a bedroom, jumped from a third-story window and fled, leaving his baseball cap behind on the grass.

Members of a regional fugitive task force arrested the suspect, identified as Jaren Nathaniel Holley, 21, of Southwest Washington, on Saturday, charging him with burglary while armed. He was ordered detained Monday during a brief appearance in D.C. Superior Court.

Holley appeared at his hearing wearing a gray-and-blue sweatshirt and jeans, his wrist and ankles shackled, looking far younger than his years. The would-be victim of the break-in described him as a “baby face” while picking his photo from a lineup.

Interest in the case was heightened because Johnson had played a role in the high-profile killing of Brian K. Betts, principal of Washington’s Shaw Junior High School, two years ago in Silver Spring.

Johnson, 21, had helped prosecutors identify the gunman, who was sent to prison for 40 years. In exchange, he pleaded guilty to accessory after the fact to murder and spent 18 months in prison.

Montgomery County Circuit Court Judge Thomas L. Craven called the plea agreement “generous” and said he didn’t believe Johnson’s claims that he didn’t know his friends were going to rob Betts that night.

“I commend you for making the best of a bad situation since your arrest, but I wouldn’t lose sleep if I sent you to Hagerstown for five years,” Craven said during the March 2011 sentencing, referring to the Western Maryland town and the Maryland Correctional Institution located there.

“I think there’s some hope in your case that you might lead a productive life,” the judge continued, according to a recording of the hearing. Noting that for Betts, “education was his life,” Craven told the defendant that “the best thing you can do to make some small good out of this is to go and get all the education you can get, and make the best man out of yourself that you can.”

The judge warned: “If anyone tempts you, you better think twice.”

Johnson said he was working toward his high school equivalency degree. Speaking to Betts’s grieving mother in court, he said: “I’m very sorry, ma’am. I didn’t know what was going to happen that night. I can’t make it right.”

He was released in April 2011 and placed on five years’ probation.

On the night of Sept. 19, authorities say, Johnson and Holley sat in wait on the apartment building’s third-floor landing. Authorities said the two accosted the man and a female companion as they returned home, the man holding groceries, and fought off the victim’s attempts to shut his door on them.

Inside, the documents say, Holley struck the victim in the head, demanded money and ordered him to lie on the floor. Authorities said Johnson chased the woman into a back bedroom but she jumped to the ground to escape, breaking her right ankle.

By the time Johnson returned to the living room, police said, Holley was locked in a struggle with his intended victim.

In the interview, the man said that he managed to avoid a punch by putting a hand up to block the blow. After his arm hit his attacker’s, he said, he was able to grab the gun. Police said that Johnson then entered the room and raised his weapon, prompting the man to fire.

Reached by phone Monday, the man spoke briefly before saying that police had advised him not to talk. The Post generally does not identify victims of crimes.

Holley’s attorney, James White­side of the D.C. Public Defender Service, argued that no DNA evidence linked his client to the burglary and that only one witness picked out his client from a photo array.

Whiteside also argued that while the court documents say that Holley fled from the apartment by jumping from the third floor, he was uninjured — unlike the woman who police said broke her ankle from the same fall.

Magistrate Judge Karen A. Howze ordered Holley detained until his next court hearing on Oct. 9.

Michael Laris contributed to this report.