MADRID (Reuters) - Catalonia’s parliament voted on Wednesday to hold an independence referendum on Oct. 1, setting up a clash with the Spanish government that has vowed to stop what it says would be an illegal vote.

Slideshow ( 17 images )

After 12 hours of often chaotic debate in the Barcelona parliament, a majority voted for the referendum and the legal framework to set up a new state, under which the assembly would declare independence within 48 hours of a “yes” vote.

Lawmakers who opposed independence abandoned the chamber before the vote, with some leaving Catalan flags in their empty seats. The winners, led by regional head Carles Puigdemont, sang the Catalan national anthem once the votes were counted.

“Committed to freedom and democracy! We push on!” Catalonia’s deputy governor, Oriol Junqueras, tweeted after the vote.

Polls in the northeastern region show support for self-rule waning as Spain’s economy improves. But the majority of Catalans do want the opportunity to vote on whether to split from Spain.

The government has asked the Spanish constitutional court to declare the referendum law void as soon as it is approved by the regional parliament. The Spanish constitution states that the country is indivisible.

“What is happening in the Catalan parliament is embarrassing, it’s shameful,” Deputy Prime Minister Soraya Saenz de Santamaria told reporters.

The details of the referendum, which would pose the question “Do you want Catalonia to be an independent republic?” to all Spanish citizens living in Catalonia, were revealed amid a tense atmosphere in the 135-seat regional parliament.

“You will not split up Spain, but you are breaking up Catalonia,” Alejandro Fernandez of the ruling People’s Party (PP) told pro-independence lawmakers. “You’re putting social harmony at risk.”

The vote comes about three weeks after Barcelona and a nearby town were struck by Islamist attacks that killed 16 people and caused the Catalan and Spanish governments to present a brief united front.

Divisions reappeared as both sides squabbled over whether either could have prevented the attacks, and rallies against terrorism became politicized. Crowds in Barcelona booed Spain’s King Felipe when he visited for one march.

There will be no minimum turnout requirement to make the result of the referendum binding, Puigdemont said in a recent briefing. Ballot boxes, voting papers and an electoral census are at the ready, he said.

Spanish Prime Minister Mariano Rajoy told a news conference on Monday the government would come down with all the force of the law to ensure no referendum would go ahead.

Courts have already suspended from office and leveled millions of euros in fines at Catalan politicians who organized a non-binding referendum in 2014, which returned a “yes” vote on a low turnout.