A “demon” Rikers Island guard shot a Massachusetts cop to death before turning the gun on himself during a bloody domestic attack yesterday, officials said.

Corrections Officer Shawn Bryan, 34, had gone to the Springfield, Mass., home of gal pal Charlene Mitchell at about 1 p.m. — just minutes after she got a restraining order against him — when the fatal encounter began.

The three were outside her building when Bryan suddenly pushed Mitchell inside, ran into the apartment and closed the door on Ambrose. When the cop tried to get inside, Bryan fatally shot him through the door, police said.

Bryan then critically shot Mitchell — whose 1-year-old daughter with Bryan was in the home at the time — before going to his car and firing a fatal shot into his chest.

Mitchell had agreed on her application for a restraining order that Bryan should have a relationship with their kid, but otherwise wanted nothing to do with him.

“I said, ‘I have nothing to say to you.’ ”

He then texted her and said, “I’m gonna make you wish you were not born” according to Mitchell, who added: “He is a demon.”

She got the restraining order against Bryan 45 minutes before the shooting.

Bryan’s co-worker, Liz Castro, said he was, “a good son and a good family member.”

The city’s Department of Correction confirmed that Bryan had been on the job since Aug. 27, 2009.