BARCELONA, Spain — At some point on Sunday afternoon, as riot police officers forced their way into polling places all over the city, the Moisès Broggi high school in Barcelona became a fortress.

The volunteers overseeing the school’s defense ranged in age from 13 to 17, and represented a number of adolescent tribes, among them hippies, punks and a subset of girls with long, dark hair who called themselves “the smokers.”

The older boys wrapped their bicycle locks around the front gate, and braced it with a barricade of wooden benches. They assessed the front door: a narrow space, easy to defend. If the police forced their way in, they would find themselves in a sort of cage, surrounded on all sides.

Two hours and three minutes remained until the polls closed, at 8 p.m. Some 2,500 completed ballots were inside, in six sealed ballot boxes. Romain Flarion, 17, scanned the street for police convoys — vehicles with blacked-out windows had passed by slowly — and rolled a cigarette, looking a little sheepish.