They were switched at death.

A horrific hospital mix-up left a Brooklyn woman grieving for nine days at the bedside of a brain-damaged man who doctors insisted was her brother — but who was actually a stranger with the same name, a new lawsuit charges.

But only after she gave consent to have her “brother” taken off life support at St. Barnabas Hospital did Shirell Powell learn the shocking truth: Her real sibling was in jail — and she had just sent a stranger to his death, her Bronx Supreme Court lawsuit says.

“I nearly fainted because I killed somebody that I didn’t even know. I gave consent,” said Powell, 48, of Crown Heights.

“I was like, ‘Where is my brother? What is going on?’ I was devastated.”

The saga began July 15, when Freddy Clarence Williams, 40, was admitted to the Bronx hospital, unconscious from an apparent drug overdose, according to Powell’s lawsuit.

Williams had his Social Security card on him, and it identified him by that name, the court papers say.

But the hospital phoned Powell anyway, telling her that her brother, Frederick Williams, who also is 40 but has no middle name, had been admitted and was near death.

She rushed to the man’s bedside.

“He had tubes in his mouth, a neck brace,’’ Powell told The Post. “He was a little swollen . . . [But] he resembled my brother so much.

“He couldn’t speak from the time they brought him in the hospital. They just assumed it was my brother.”

After two days of tests, St. Barnabas doctors told her that her “brother” was brain-dead, she said.

“That is my baby brother, so it was really hurtful,” she said. “I was worried, hurt, crying, screaming, calling everybody. It was a horrible feeling.”

With no cause to hope for his recovery, she contacted relatives down South, telling them to come and say their goodbyes.

Powell acknowledged that the first time her sister saw the ailing man in the hospital, she questioned whether he was their sibling.

“She walked up into the room and said, ‘That is not my brother,’ ” Powell recalled. “I said, ‘What do you mean?’ ”

“The guy was much bigger,’’ Powell explained.

But he appeared swollen, and “the eyebrows, the nose, the structure — it looked like [our] brother,” Powell said. “My sister, she walked up closer, and you could see the resemblance, and she was like, ‘Oh, OK.’ ”

So on July 29, with her uncle and sister at her side, Powell “authorized [the hospital] to withdraw life support from Frederick Williams,” the lawsuit says.

“It was very devastating,” she recalled. “I was crying.”

Frederick Williams’ “death” was even harder on his two daughters — Brooklyn, 17, and Star, 18, their aunt said.

The teens live in Virginia, and Brooklyn came to the city to say goodbye to her father before he was taken off life support, Powell said.

“She was hysterical,” Powell recalled. “She was holding his hand, kissing him, crying.”

Only after an autopsy did the city Medical Examiner’s Office reveal the truth: The dead man was Freddy Clarence Williams.

Powell said they got a call from a worker at the agency as they were making funeral arrangements.

“She called us just in time,” Powell said. “We would have been burying someone else.”

Meanwhile, it turned out Powell’s actual brother was in jail on a July 1 assault arrest in lower Manhattan.

Powell went to Manhattan Supreme Court for her sibling’s next hearing a few weeks later — just to lay eyes on him.

“I saw my brother,” she said. “I couldn’t believe it. I was very relieved.”

She also called him on the phone at Rikers Island. They had quite a conversation about her decision to pull his plug.

“How could the hospital do something like that? Look what they put my family through.”

“He was saying, ‘You were going to kill me?’ I explained to him, once you’re brain-dead, there is nothing to do.”

Interviewed at Rikers, Powell’s brother said he had forgiven his sister for pulling the plug on the man she thought was him.

“The doctors told her they couldn’t do anything,” he said. “I’m not mad at her.”

Still, he raged, “How could the hospital do something like that? Look what they put my family through.”

Powell’s lawyer, Alexander M. Dudelson, told The Post that he tried to get information about Freddy Clarence Williams, the stranger who died surrounded by Powell’s sobbing family.

“The representatives [at St. Barnabas] basically spit in my face,” he said. “This is beyond reckless conduct. I requested an investigation. Nothing more. An apology would have been nice.”

Asked about the lawsuit, which seeks unspecified damages, hospital spokesman Steven Clark responded, “We don’t feel there is any merit to this claim.”

Powell also asked the ME’s Office for the dead man’s family information so she could send condolences, but it denied the request, citing privacy concerns.

Now, Powell says, she remains haunted by questions: The man she had grieved for at the hospital — who was he? Does he have family?

“I barely sleep thinking about this all the time,’’ she said.

“To actually stand over him and watch this man take his last breath — sometimes I can’t even talk about it because I get upset and start crying.

“On the one hand, I’m thankful that it wasn’t [my brother]. On the other hand, I killed somebody that was a dad or a brother.”