BRUSSELS -- European Union lawmakers on Thursday accused Morocco of endangering the lives of children in an attempt to put political pressure on Spain, after more than 8,000 people tried to cross into Spain's North African enclave of Ceuta last month.

In a 397-to-85 resolution with 196 abstentions, the lawmakers urged the government in Rabat and the EU's executive branch, the European Commission, to rapidly finalize a "readmission" agreement so migrants can in the future be returned legally.

They say 1,200 unaccompanied minors were among those who tried to enter Ceuta by scaling a border fence or swimming around it. Morocco has since taken back most of the migrants. Entering the enclave put them in EU territory, where they could try to apply for asylum.

The surge of migrants took place after Spain agreed to provide medical treatment for the Sahrawi leader heading the fight for an independent Western Sahara, which was annexed by Morocco in the 1970s. Rabat reacted furiously and recalled its ambassador in Madrid.

The lawmakers rejected "Morocco's use of border control and migration, and unaccompanied minors in particular, as political pressure" against an EU nation. They deplored that children and families had been involved in the crossing, "putting their lives and safety at clear risk."

In the nonbinding resolution, they urged Spain and Morocco to work closely together to allow for the repatriation of the children to their families, acting in the best interests of the child and respecting national and international law.

The Associated Press and other media witnessed several incidents in which the Spanish authorities in Ceuta sent many migrants who did make it in back to Morocco, including a lot of children. Human rights organizations say those actions are illegal.

The EU lawmakers also expressed regrets about the damage to ties with a near neighbor who has a good track record of cooperation with the 27-nation bloc on trade, counter-terrorism and drug trafficking.

In the days before the resolution was adopted, Moroccan officials expressed concern that its bilateral issue with Spain might take on a broader European dimension and they urged lawmakers to tone down their criticism.

Chaoui Belassal, head of the EU-Morocco Joint Parliamentary Committee, said this week that "Morocco is fulfilling its commitments" toward the bloc, which provides significant development and migration aid to the country.

He emphasized the "great efforts made by Morocco with regard to all issues that fall within its relations with the European Union, including immigration, the fight against extremism, terrorism (and) money laundering."

------

Tarik El Barakah in Rabat, Morocco contributed to this report.