The girl told investigators Martin, whom she knew, got her to go into the back of a stairwell by grabbing her jacket and backpack, police sources said. “He lured her in a playful manner, taking her backpack and running behind the staircase,” a source said.

But Martin then allegedly pushed her to the ground and raped her.

The girl, a junior, quickly reported the incident and was taken to a local hospital, cops said.

Martin was arrested around 12:30 p.m. at the school and charged with first-degree rape. He had no prior arrests, police sources said.

“This troubling incident was immediately reported, and we are working closely with the NYPD as they conduct an investigation,’’ DOE spokeswoman Miranda Barbot said. “We are treating this with the utmost seriousness and are providing the campus with additional guidance and safety supports.”

Martin was arraigned on the rape charge, as well as for alleged sexual misconduct and endangering the welfare of a child, in Manhattan Criminal Court. The judge also issued a protective order for his accuser.

Martin was held on $10,000 bail as his mother looked on.

The suspect’s lawyer, Lorin Nathan, described his client as a B- student “with no criminal history whatsoever.

“The prosecution contends after forcibly raping a fellow student at 8 in the morning he attended all of his classes,’’ Nathan said. “We believe there may be surveillance inside the school. I suspect [the prosecution] will show a picture of what is alleged here.

“These are allegations that are very easily made,’’ Nathan said. “When allegations such as these are made, often times there are ulterior motives that do not correspond with the truth.”

Both teens attend Gramercy on the campus, which houses multiple other schools including the High School for Language and Diplomacy, the Academy for Software Engineering and the International HS at Union Square.

Friends of Martin’s rallied to his side. “He’s a good kid, he’s a real good kid,” said a 16-year-old Gramercy student who only gave her first name, Shaniyah.

“He’s not disrespectful to women. “A lot of girls like him. He’s not the type to do that.”