An 18-year-old student stabbed two classmates after an argument erupted during class at a Bronx school Wednesday morning, killing one boy and seriously wounding another, officials said.

The victims — ages 15 and 16, who were both stabbed in the chest — were rushed to St. Barnabas Hospital in the Bronx. The younger boy died on arrival, while the other boy is in critical condition, officials said. The alleged attacker is in police custody.

It was the first time one student killed another inside a city school in nearly 25 years, according to the mayor’s office. In 2014, a 14-year-old boy fatally stabbed another boy outside I.S. 117 in the Bronx.

The stabbing on Wednesday occurred about 10:45 a.m. at the Urban Assembly School for Wildlife Conservation, a grade 6-12 school in the West Farms section of the Bronx. The school shares a building with P.S. 67, which includes preschool to fifth grade.

“My heart goes out to the families who have been affected by this tragedy,” Mayor Bill de Blasio said at a press conference in the Bronx Wednesday afternoon, where he was accompanied by schools Chancellor Carmen Fariña and Police Commissioner James O’Neill.

“It has been many, many years in this city since we lost a child in a school in this kind of violent incident,” de Blasio added, “and it’s all the more troubling for that reason.”

The students had been arguing for the past few weeks, police officials said at the briefing. The argument escalated Wednesday, culminating with the attack about 30 minutes into a history class.

The attacker used a switchblade knife with a 3-inch blade that he brought into the school building, which does not have metal detectors. He walked into the hallway after the attack and encountered a guidance counselor, who asked him to hand over the knife. Then he waited in an assistant principal’s office until police arrived, officials said.

The city will send extra security officers to the school beginning tomorrow, where they will conduct random weapons screenings, de Blasio said. Officials said they would review whether the school should have permanent metal detectors, though de Blasio said the school has been “very safe” in the past.

The city sent letters home Wednesday with the roughly 1,100 students in the building, Fariña said. It will dispatch grief counselors to the school Thursday.

“This is a school we will be closely supporting in as many different ways as possible,” she said.

After the incident, parents raced to the school to check on their children. According to videos posted online, large crowds gathered outside the building entrances demanding to be let in, while police officers tried to calm them. Once they were allowed to pick up their children, some parents were emotional and called on the city to install metal detectors at the school, according to NY1 reporter Lindsey Christ.

Later in the day, de Blasio and Fariña met with staff and parent leaders at the school. In a school survey last year, 76 percent of students said they felt safe in their classrooms, compared to 91 percent of students citywide; 55 percent said they felt safe in the school’s hallways, bathrooms, locker rooms, and cafeteria, compared to 84 percent citywide.

Alex Zimmerman contributed reporting.