A doctor whose wife was killed in Saturday’s synagogue attack had started emergency CPR on her — unaware of whom he was helping, according to a family friend.

Shooting victim Lori Gilbert-Kaye, 60, had been with her husband celebrating Passover at the Chabad of Poway Synagogue near San Diego when authorities say gunman John T. Earnest, 19, burst in and opened fire with “an AR-type weapon.”

Unaware that his wife had been fatally wounded when she leaped in front of Brooklyn-born Rabbi Yisroel Goldstein, saving his life, her physician hubby raced over to help victims of the bloodbath.

He started emergency CPR on one woman — unaware she was his wife, family friend Dr. Roneet Lev told the San Diego Union-Tribune.

The doctor fainted when he realized the victim was his spouse, Lev said.

Lev said Gilbert-Kaye, the mom of a 22-year-old daughter, had gone to the synagogue also to say Kaddish, a Jewish prayer for the dead, for her own mother, who had recently passed away.

“The irony is people will be saying it for her now,” Lev, director of emergency operations at San Diego’s Scripps Mercy Hospital, told the paper.

“God picked her to die to send a message because she’s such an incredible person.

“He took her for a higher purpose to send this message to fight anti-Semitism.”

Earnest was arrested after the shooting, which also injured three others, including the rabbi and an 8-year-old girl.

An online manifesto suggests he was inspired by the mass shooting at a New Zealand mosque that killed 50 Muslims on March 15.