The Bronx High School of Science welcomed an unusual visitor to its campus recently — and it wasn’t one of its eight Nobel Prize-winning alumni or a Harvard recruiter.

It was an undercover cop, acting on a tip, the Department of Education confirmed.

While officials said he spoke to administrators and quickly left the building, students said the plainclothes cop lingered in the cafeteria for most of the day. He was quickly “made” by the students, partly because of his age, and his photo was widely circulated on pupils’ social media.

Whatever the cop’s mission was, Bronx Science is seeing an uptick in trouble.

Last week a student was sent to the hospital after fellow students punched and kicked him repeatedly in the head, according to the NYPD.

Cops charged Arian Ali, 17, and an unidentified 16-year-old with assault after the 1:30 p.m. Tuesday brawl. The NYPD said the fight stemmed from an unspecified dispute that happened about a month ago.

“We’ve taken appropriate disciplinary action in response to this isolated incident, and are working with the family to provide ongoing support,” said a DOE spokeswoman.

Bronx Science is one of the eight specialized high schools that requires an admissions exam for entry.

The elite schools can often be pressure cookers with high demands on students to do well and get into good colleges. Seniors wore shirts Friday with the names of the schools they would attend next year including MIT, Harvard and the University of Chicago.

The school has had issues with the rampant use of e-cigarettes, which some staffers believe students fill with marijuana oil.

“The safety and well-being of our students is our top priority, and we’re hiring a new, full-time substance abuse prevention and intervention counselor at the school,” the DOE spokeswoman said.

One Bronx Science teacher said students were turning to the e-cigarettes as stress relievers, vaping in school bathrooms.

“There’s a huge problem in terms of Juul smoking,” the teacher said, adding the e-cigarettes were sometimes traded illegally.

The school even shut down some restrooms in remote areas of the building last fall where students were hiding out to vape.

But students interviewed last week said the bathroom ban was brief.

As for the undercover cop, students said he needs to adjust his wardrobe.

He “walked into our school with a beanie on and our school does not allow hats,” a student said. “And he wore it all day.”

Additional reporting by Stephanie Pagones