A 15-year-old boy was repeatedly stabbed inside a Brooklyn school Wednesday afternoon after he desperately ran into the building to escape his attacker, officials said.

The victim, who is in stable condition, got into an altercation with a 16-year-old student outside JHS 292 in Brownsville at 3:15 p.m., according to Greg Floyd, president of the school safety agents union.

The younger boy attempted to flee the fight and scampered into the Vermont Street school with his blade-waving assailant in hot pursuit, Floyd said.

The attacker managed to stab the boy in the head, torso and arm with a kitchen knife before school safety agents pulled him off and prevented further damage.

He was rushed to Brookdale Hospital where he was treated for his wounds and is listed in stable condition.

The alleged stabber was arrested by arriving NYPD cops and transported to the 75th precinct.

“Safety always comes first, and the NYPD and EMS immediately responded to this serious incident that occurred after school,” said Department of Education spokeswoman Miranda Barbot. “We are working closely with NYPD and will provide additional safety supports to the school.”

The summer school stabbing comes after city campuses saw a sharp hike in weapons confiscations during the 2017-2018 school year.

The total number of weapons seized shot up by 28 percent over the previous year, spiking from 2,119 to 2,718, the NYPD told The Post.

While gun confiscations dipped from 10 to five, staffers recovered a whopping 1,551 knives – up from 1,176 during the prior year.

Box-cutter busts also rose 27 percent – from 607 to 771, according to the NYPD.