The deranged 19-year-old accused of the worst school shooting since the Sandy Hook massacre may have been sent over the edge when his single mom died of complications from the flu in November, family said.

Suspect Nikolas Cruz, 19, is accused of killing 17 and injuring more than 15 when he opened fire inside South Florida’s Marjory Stoneman Douglas High School on Wednesday.

He and younger brother Zachary were adopted as infants by Roger and Lynda Cruz, but Roger died from a heart attack a decade ago, leaving Lynda to raise the boys herself, according to family.

Lynda, 68, checked into a clinic with the flu and was rushed to a hospital, where she died Nov. 1 of pneumonia, cousin Kathie Blaine told ABC News.

She was otherwise healthy before checking into the hospital, the cousin told the network.

“Lynda was very close to them,” sister-in-law Barbara Kumbatovic told the Washington Post. “She put a lot of time and effort into those boys, trying to give them a good life and upbringing.

“I don’t think it [the massacre] had anything to do with his upbringing. It could have been the loss of his mom.”

She recalled how Nikolas once sicced his dog on a neighbor’s pig — and how Lynda tried to discipline the boy but may have fallen short.

“He sent over his dog . . . to try to attack them,” Kumbatovic said. “Lynda dealt with it like most parents did. She was probably too good to him.”

An anonymous family member told the Sun-Sentinel that Nikolas had been diagnosed with autism.

“I know he did have some issues and he may have been taking medication. [He] did have some kind of emotional problems or difficulties,” Kumbatovic also told the paper.

After the unexpected death, the brothers briefly moved in with friends in Palm Beach County, but Nikolas left shortly afterward when a friend’s family said he could stay with them in northwest Broward County, the Sun-Sentinel reported.

He had already been expelled from Stoneman Douglas — where his friend still attended school — and the family encouraged him to take adult education courses and helped him get a job at a local dollar store, according to family attorney Jim Lewis.

“The family is devastated, they didn’t see this coming,” he said, according to the Sun-Sentinel. “They took him in and it’s a classic case of no good deed goes unpunished. He was a little quirky and he was depressed about his mom’s death, but who wouldn’t be?”

Nikolas already owned the AR-15 assault rifle he allegedly used in the massacre when he moved in with the family, and they made him keep the weapon in a gun safe, CNN reported.

The family handed over the safe keys to investigators, the outlet reported.