BARCELONA, Spain — Catalonia’s defiant attempt to stage an independence referendum descended into chaos on Sunday, with hundreds injured in clashes with police in one of the gravest tests of Spain’s democracy since the end of the Franco dictatorship in the 1970s.

National police officers in riot gear, sent by the central government in Madrid from other parts of Spain, used rubber bullets and truncheons in some places as they fanned out across Catalonia, the restive northeastern region, to shut down polling stations and seize ballot boxes.

The clashes quickly spoiled what had been a festive, if expectant, atmosphere among voters, many of whom had camped inside polling stations and stayed on into late Sunday night, fearful that officers might seize ballot boxes.