Police said officers responding to a burglar alarm at Teaneck High School shortly after 2 a.m. also found desks flipped over, chairs broken, graffiti on the walls, silly string on the floors and balloons throughout the building.
Even before they went inside, police said, officers could see many students through the building's windows.
Police from more than a dozen neighboring towns plus county law enforcement officers were called in to help.
They used police dogs in their room-by-room roundup of students, some of whom were hiding.
"It is possible that a few got away, but the majority were caught," Acting Police Chief Robert Carney said.
He said the students told officers that it was a senior prank - an annual tradition at the northern New Jersey school of 1,300 students, though it is usually not this involved. As they were arrested, Carney said, some students were scared but others were laughing.
"If this was a senior class prank, I just don't believe that a lot of them realize the seriousness of it as far as breaking into the building," Sgt. John Garland said. "That's a burglary and I don't think they understand that. It's a very serious offense."
The 24 students who are 18 or older were charged with burglary and criminal mischief. The other 38 are juveniles and are being released to their parents.
Teaneck school superintendent Barbara Pinsak said at a news conference that the district is also considering disciplining students.
"The district continues to assess the situation and is considering the consequences that we'll impose on any students implicated," she said.
Pinsak said the school was cleaned up in time for classes on Thursday.