Spain's Prime Minister has warned that he will not rule out imposing direct rule on Catalonia if its government continues to threaten to declare independence.

Mariano Rajoy has said he will not “rule out anything” when it comes to solving the constitutional crisis which has gripped the country since the referendum result last week. He said Madrid may have to resort to "drastic solutions" to restore order.

The referendum on independence called by the Catalan government, deemed illegal by Madrid, saw an overwhelmingly majority vote to split from Spain.

But voting was marred by violence as Spanish police tried to prevent to people from voting, blocking the entrance to polling stations and removing ballot boxes.

National Civil Guard officers, brought in by Madrid which did not trust the local force Mossos d' Esquadra to stop the vote, fired rubber bullets into crowds of protesters.

At least 860 people were injured in the clashes which were condemned by a Catalan President Carles Puigdemont. He said the violence meant “the Spanish state wrote another shameful page in its history with Catalonia”.

Last week, he said he planned to formally declared independence from Spain "at the end of this week or the beginning of next", while also calling for international help in solving the crisis through mediation.

But Mr Rajoy defended the actions of the Civil Guard in a television address where he said the police response was appropriate because a referendum “did not take place in Catalonia” as it had already been declared illegal by the Constitutional Court in Madrid.

The court found the vote violated a clause in the constitution which refers to “the indissoluble unity of the Spanish nation, the common and indivisible homeland of all Spaniards”.

Catalonia independence referendum: Riot police clash with voters Show all 17 1 /17 Catalonia independence referendum: Riot police clash with voters Catalonia independence referendum: Riot police clash with voters A man faces off Spanish Civil Guards outside a polling station in Sant Julia de Ramis Reuters Catalonia independence referendum: Riot police clash with voters Riot police form a security cordon around the Ramon Llull school in Barcelona EPA Catalonia independence referendum: Riot police clash with voters Riot police evict a young woman during clashes between people gathered outside the Ramon Llull school in Barcelona EPA Catalonia independence referendum: Riot police clash with voters Spanish Civil Guard officers break through a door at a polling station in Sant Julia de Ramis Reuters Catalonia independence referendum: Riot police clash with voters Spanish National Police clash with pro-referendum supporters in Barcelona on Sunday AP Catalonia independence referendum: Riot police clash with voters Crowds raise their arms up as police move in on members of the public gathered outside to prevent them from voting in the referendum at a polling station where the President Carles Puigdemunt will vote later today Getty Catalonia independence referendum: Riot police clash with voters People confront Spanish Civil Guard officers outside a polling station Reuters Catalonia independence referendum: Riot police clash with voters Three man hold each other as they try to block a Spanish police van from approaching a polling station AP Catalonia independence referendum: Riot police clash with voters A woman shows a ballot to a Spanish Civil Guard officer outside a polling station Reuters Catalonia independence referendum: Riot police clash with voters A man wearing a shirt with an Estelada (Catalan separatist flag) and holding carnations faces off with a Spanish Civil Guard officer Reuters Catalonia independence referendum: Riot police clash with voters Police try to control the area as people attempt to cast their ballot at a polling station in Barcelona Getty Catalonia independence referendum: Riot police clash with voters A man is grabbed by officers as police move in on the crowds Catalonia independence referendum: Riot police clash with voters Two women argue with a Spanish National policeman during clashes between Catalan pro-independence people and police forces at the Sant Julia de Ramis sports centre in Girona EPA Catalonia independence referendum: Riot police clash with voters Sant Julia De Ramis in Spain Getty Catalonia independence referendum: Riot police clash with voters Confrontation outside a polling station in Barcelona, where police have tried to stop people voting AFP/Getty Images Catalonia independence referendum: Riot police clash with voters A Spanish National Police officer aims a rubber-bullet rifle at pro-referendum supporters in Barcelona AP Catalonia independence referendum: Riot police clash with voters Riot police clashed with voters as polls opened in Barcelona Sky News

He was defended by the Spanish King, Felipe, who accused the Catalan government of an “inadmissible lack of loyalty” and said the situation was “very serious” but believed the country “will overcome difficult times”.

Speaking to Spanish newspaper El Pais, Mr Rajoy said Spain would “absolutely not” split up.

He said: “Spain is not going to divide and national unity will be maintained. To do so we will use all of the instruments that the legislation gives us. It falls to the government to take the decision and to do so at the right time. We have listened to a lot of people.

“We believe that we know what the Spanish people are thinking. And they should know that the government also knows what it has to do.”

He said with “complete clarity” that Madrid is “going to stop independence from taking place”.

“I want to say one thing with complete clarity: while the threat of a declaration of independence does not disappear from the political panorama it is going to be very difficult for the government not to make decisions”, he warned.

When asked whether this meant he would trigger Article 155 of the Spanish Constitution, which means the central government can take direct control of an autonomous region which declares independence, he said he would not “rule anything out”.