Police worked through the night to secure the border around Spain's North African exclave of Melilla after hundreds of migrants attempted to cross from Morocco, days after tens of thousands entered Spain's other exclave, Ceuta.

Images broadcast by Spanish state broadcaster RTVE showed several police cars driving along the border in Melilla with their blue lights flashing.

About 500 people attempted to enter Melilla on Friday evening, RTVE reported. Security forces were deployed, and around two hours later, at about 9 pm (1900 GMT), another group tried to breach the border fence.

According to the report, several migrants threw stones at officers, who responded with tear gas. It was initially unclear whether any of the migrants had succeeded in entering Melilla. The Beni Enzar border crossing has been closed since Thursday evening.

Meanwhile, the situation in Ceuta, about 370 kilometres west along the Moroccan coast, had eased significantly following the recent influx.

Some 50,000 people had entered the exclave from Morocco by Friday morning, many of them by swimming, according to Spanish authorities.

But tens of thousands of them have since voluntarily returned, according to Madrid, which has faced a major backlash from some conservative European leaders over the breach of what is also an external EU border.

An unknown number of migrants remain in Ceuta, home to around 85,000 people.

The North African coastal cities of Ceuta and Melilla have been under Spanish control for centuries.