Spain and Morocco have taken further steps to jointly combat terrorism and illegal immigration by appointing judges to work in each other's country.
Morocco has started to clamp down on migrants heading for Spain
A Spanish magistrate based in Rabat will send judicial information back to Spain, while the Moroccan judge does the same from Madrid.
The Spanish Interior Ministry hopes the project will help to clarify events surrounding the Madrid train bombings.
Morocco, meanwhile, has recently been clamping down on illegal immigrants.
The Spain-Morocco exchange is the first agreement of its kind with a non-European nation.
Spanish Interior Minister Juan Fernando Lopez Aguilar told reporters: "We can only hope these liaison judges will help... with the co-operation necessary for the complete clarification of the terrible events of 11 March and the prosecution of those responsible."
An Islamic group with links to al-Qaeda is blamed for the attacks in March, which killed 191 people. Most of the suspects still being held in Spain are of Moroccan origin.
The two countries, separated by the Straits of Gibraltar, hope the exchange of information will also help tackle organised crime, particularly trafficking of illegal immigrants who enter Spain by sea.
"The spectacular growth of illegal immigration from the Maghreb region and from Morocco in particular is enormously worrying for Spain and requires sharing information on the networks which smuggle people," said Mr Lopez Aguilar.
The Spanish liaison judge will be Angel Jose Llorente Fernandez de la Reguera - an expert in international legal co-operation and immigration, according to the Spanish news agency Efe.
His Moroccan counterpart will be Naziha Harrak, a specialist in human rights.
Morocco recently conducted a three-day roundup of 148 people planning to
reach Europe illegally, according to the official MAP news agency.
Moroccan Justice Minister Mohamed Bouzoubaa said Rabat had successfully broken 365 immigrant trafficking rings this year and arrested more than 3,700 potential illegal immigrants. But he insisted the problem required greater international co-operation.
Relations between the two countries have warmed since the Socialist government came to power in Madrid in March, and they have been conducting joint patrols of the Straits of Gibraltar.
On Thursday, European Union ministers are discussing whether asylum seekers could be processed outside the EU in the so-called "transit camps".
One suggestion is to set up processing centres - notably in North Africa - where would-be immigrants could go for their cases to be considered.