Mariano Rajoy | Cesar Manso/AFP via Getty Images Mariano Rajoy: When UK leaves EU, Scotland goes with it Spanish prime minister ‘extremely against’ talks between Edinburgh and Brussels.

Spanish Prime Minister Mariano Rajoy said Wednesday Madrid would oppose any separate negotiations between Scotland and the EU in the wake of the Brexit vote.

"The United Kingdom leaves and with it all those who make up the United Kingdom," Rajoy said after a meeting of 27 EU leaders in Brussels.

"I want to be very clear … Scotland does not have the competence to negotiate with the European Union."

"I am extremely against it, the treaties are extremely against it and I believe everyone is extremely against it. If the United Kingdom leaves ... Scotland leaves," he said.

Scottish First Minister Nicola Sturgeon is to hold talks with the leaders of the European Commission and European Parliament on Wednesday. Scotland voted overwhelmingly (62 percent) in favor of staying in the EU, reviving talk of another referendum on independence from the U.K.

Rajoy's conservative Popular Party won the most seats in a general election on Sunday, but fell short of a governing majority. All the major Spanish parties — with the exception of the far-left Podemos — are against an independence referendum in Catalonia.