Spanish Prime Minister Mariano Rajoy called on Monday for stepped-up cooperation between Europe, North Africa and the Middle East to confront illegal immigration and what he called "terrorist barbarism".
Rajoy made the call at a meeting of foreign ministers from the 28 EU countries and eight countries on the southern rim of the Mediterranean. It was the largest gathering of its kind since 2008.
The meeting responds to pressure from southern European countries such as Spain and Italy for the EU, preoccupied by the Ukraine crisis for the past 18 months, to put more energy into dealing with threats and problems emanating from the south.
Conflict in North Africa and the Middle East has prompted a wave of migration, which has led to thousands drowning in the Mediterranean and has stretched the resources of countries such as Italy. Security officials say Europe faces a growing threat from groups such as Islamic State gaining a foothold in Libya.
"Jihadist terrorism is a direct threat for the security of our countries and our citizens and without doubt is our main threat right now," Rajoy said, opening the one-day conference in the elegant Pedralbes palace in Barcelona.
"I am convinced that a shared commitment between both shores of the Mediterranean will allow us to defeat terrorist barbarism," he said, urging measures to avoid radicalisation, to stop foreign jihadists going to fight in Iraq or Syria, and to restrict sources of financing for militant groups.
Spain was the site of one of Europe's worst attacks in 2004 when Islamist militants killed nearly 200 people in bombings of commuter trains.
Members of a suspected Islamist cell arrested last week in Spain were trying to obtain explosives to bomb a synagogue or public offices in Barcelona, an investigating magistrate said last Friday.
Rajoy said cooperation with countries of origin and transit was the only way to tackle the migration problem and he also called for efforts to narrow the large wealth gap between countries to the north and south of the Mediterranean.
Algeria, Egypt, Israel, Jordan, Lebanon, Morocco, the Palestinian Authority and Tunisia sent representatives to the meeting while the EU's other two southern partners, Libya and Syria, both torn by conflict, stayed away.
The goal of Monday's meeting is to share views on how the EU can revamp its policy towards its southern and eastern neighbours that dates back to 2003 and is judged to be out of date.