Bronx cabby Mamadou ­Diallo was looking for a parking spot outside his building when he got a call from his wife that filled him with shock and fury.

She said a stranger had just tried to rape her in their apartment — and was still upstairs.

Diallo grabbed a tire iron and did what most husbands in the same situation would do: He rushed to his wife’s aid and then bludgeoned the pervert.

The attack killed career criminal Earl Nash, 43 — and left ­Diallo facing assault and weapons charges Tuesday.

“He threatened my wife,” ­Diallo explained as he was led out of the 42nd Precinct station house in handcuffs.

“He threatened my wife,” he said again.

Nash first knocked on the ­Diallos’ apartment door in Clare­mont Village at about 9:15 p.m. Monday. The livery cabby’s wife, Nenegale — who was home with a female cousin — assumed it was her 16-year-old son.

When she saw it was a stranger, “she went to shut the door, and the guy pushed in the door and then punched her,” said Mamadou’s brother, Ibrahima, 52.

“I don’t want money — I’m going to rape you,” Nash told her, according to an account Nenegale gave to DNA Info.

Nash slugged her in the face several times before ripping off her clothes and tossing her to the floor, police sources said.

“Please, anything you want, I give you,” Nenegale remembered saying, while being pummeled by Nash. He even hit her with a chair, she said.

“He broke all of my clothes. I had no clothes at the time,” Nenegale explained. “[I was] very dizzy at the time.”

Nenegale’s cousin helped fight Nash off, and the half-naked woman called her husband.

“I took my phone and see my husband’s number first,” Nenegale said. “I pressed the number. I made a loud noise, screaming, ‘Please, help me! Help me! Call the police!’ Then he slapped me again. The phone [was] falling, but I was making noise so my husband could hear the noise.”

Mamadou Diallo — a native of Guinea and a longtime livery driver — was hunting for a parking spot on the street and ran inside with the tire iron, fearing for his wife’s life.

He took an elevator to the sixth floor — where he came face to face with Nash, who was shirtless in the hallway.

Surveillance footage shows Mamadou walk past Nash, but wheel around when Nenegale pointed him out as the attacker.

The enraged husband swung the weapon at Nash — driving him into the elevator. He followed with several more blows, in a beating that lasted up to two minutes, sources said.

Nash fought back with a belt, but the pounding left him with a fractured skull, sources said.

Emergency responders rushed Nash, who also had severe body trauma, to Lincoln Hospital, where he died from his injuries.

Diallo was initially charged with manslaughter by cops, but during his arraignment at Bronx Criminal Court, the charges were dropped to two counts of assault, harassment and criminal possession of a weapon.

“This was not an offense where the defendant committed an aggressive act,” defense attorney Anthony Michaels said. “This was an attack on his family, in his house under extreme circumstances.”

At the hearing, which was attended by more than a dozen members of Diallo’s family and mosque, prosecutors didn’t ask for bail, and instead said they would agree to whatever Judge Julio Rodriguez thought was best. He released Diallo on his own ­recognizance.

“It was self-defense,” said his 22-year-old son, who didn’t give his name. “Anyone would have done the same to protect their family. You’re going to defend them. Who wouldn’t do that to protect their wife or mom?”

Diallo’s brother agreed — saying he, too, believed his sibling’s actions were justified.

“I don’t think he’s going to be charged,” Ibrahima said. “Somebody comes to your house to kill you, what do you do? It’s your last minute — you do everything to survive.”

Diallo’s nephew described him on Tuesday as a devoted family man, saying he made a tragic mistake in the heat of the moment.

“My uncle, he didn’t intend to take anybody’s life,” the nephew said, refusing to be named. “Any one of us in that position would do the same thing to protect their family.”

A close friend of Diallo’s said he was a “good guy” who worked hard as a livery cab driver for 20 years.

“He’s been in this country 27 years and never had a problem with anyone,” said the friend, adding that Diallo is “innocent.”

Diallo’s neighbor said that “he did what he was supposed to do.”

“I saw him right after it happened,” he said. “He saw his wife with the blood and screaming for his help, and he did the right thing.”

Additional reporting by Shawn Cohen, Kevin Fasick, Larry Celona and Shari Logan