A father and his friend were stabbed outside a Brooklyn middle school after an argument over bullying between two families, police sources said.

Peter Tozzi was allegedly knifed by Pedro Ramos when the two agreed to meet and settle a score in a park behind PS 229 Dyker in Bath Beach at about 5 p.m. Sunday, according to law-enforcement sources.

“I saw blood gushing out of his chest, blood spitting out of his mouth,” Tozzi’s wife, Yanira, told The Post. “He was slumped over, going in and out of consciousness.”

Tozzi, 42, and Ramos, 37, both showed up with reinforcements: as Tozzi brought a friend, Angel Algarin, 46, while Ramos brought Kim Kelly, 35, the sources said.

Tozzi and Ramos had been beefing with one another for years over women and bullying among their teen daughters, the sources added.

And both men have dated the same woman, according to the sources.

On Sunday, Kelly allegedly handed a knife to Ramos as the two rivals were brawling behind the school, authorities said.

Ramos allegedly plunged the blade into Tozzi’s neck and chest, sources said.

Algarin was knifed in the left leg, police sources said.

Tozzi’s wife said she ran to the scene after her daughter told her about the stabbing.

The dad suffered grave injuries and was rushed to NYU Langone Hospital-Brooklyn in critical condition.

Algarin was taken to Maimonides Medical Center in stable condition.

Kelly and Ramos fled from the fight, but later turned themselves in at the NYPD’s 62nd Precinct station house.

They were arrested and each was charged with attempted murder, cops said.

The pair told police that they were not involved in the fight.

But investigators later determined both were responsible for the stabbings, sources said.

Ramos and Kelly were charged with attempted murder, cops said. They were awaiting arraignment Monday night.