SABADELL, Spain — In a mass act of civil disobedience, an army of parents and their children occupied thousands of polling stations across Catalonia on Saturday, hoping to thwart efforts by the central government to shut down an independence referendum that Madrid calls illegal.

The remarkable occupation of elementary and high schools, which in Spain serve as polling stations, set the stage for an almost surreal confrontation between pro-independence Catalans and their central government.

The defenders of the vote were ordinary, over-extended and stressed parents from the neighborhoods, who carried babies on their hips and entreated rambunctious children to stop teasing their siblings.

As the occupiers were gulping coffee and sharing plates of pastries brought by volunteers, police units Saturday started to sweep the schools to warn parents that the buildings must be emptied by 6 a.m. Sunday, three hours before the controversial plebiscite is scheduled to begin.

As children in playgrounds ran around chasing soccer balls and scribbling with crayons in classrooms, their parents huddled in the hallways, sneaking a quick cigarette, scrolling their mobile phones and worrying.

“I would not deny that we are nervous because we don’t know what is going to happen,” said Roger Serra, a parent who spent the night at Enric Casassas primary school alongside about 50 others.

The people who came to occupy the buildings to defend the referendum were almost in disbelief that in a prosperous, stable and globalized country in Europe in 2017, they suddenly found themselves at a modern-day version of the old barricades.

The families spent a restive night, watching Disney movies and curled in sleeping bags.

Catalonia’s secessionists, led by the region’s pro-independence president Carles Puigdemont, vow to press ahead with the vote in rebellion against the central government in Madrid and the Constitutional Court, which has declared the referendum illegal and the results illegitimate.

Spanish Prime Minister Mariano Rajoy has moved thousands of national police and Guardia Civil militia into Catalonia to stop the plebiscite.

National security forces have confiscated more than 13 million ballots, shut down websites, arrested 14 functionaries and demanded the region’s 700 mayors desist from supporting the vote.

On Saturday, national police took over the regional government’s telecommunications center in Barcelona.

A court in Barcelona ordered Google to delete a mobile app the Catalan government was using to distribute information about how and where to vote.

Officials with the central government said police had secured 1,300 of 2,315 schools in Catalonia used as polling stations.

“Can we vote or not? For me the great question is who is going to bring the ballot boxes and ballot papers? Will they come from a hidden place, some clandestine, secret place, that could be in our town and from there they are going to distribute it? I don’t see how this will work,” said Victor Colomer, who spent the night in the school with his wife.

The regional government has printed millions of ballots and stashed them around Catalonia. Alongside the hidden ballots are thousands of plastic tubs, marked with the Catalan regional government’s emblem, with numbered, red strips normally used to the secure the ballots.