Madrid said it would accept 60 people, while Portugal offered to welcome 30, with the remainder distributed between France, Germany and Luxembourg, government sources in Malta and Spain said.
“Spain has coordinated a pioneering agreement with six countries to distribute the reception of the people of the Aquarius.. Spain will receive 60 people,” Spanish PM Pedro Sanchez wrote on Twitter.
Malta confirmed afterwards it would allow the ship to dock to disembark its passengers, many of whom are unaccompanied children from violence-wracked Somalia and repressive Eritrea.
“Malta will be making a concession allowing the vessel to enter its ports, despite having no legal obligation to do so,” said a government statement posted on Twitter.
Malta had at the end of June agreed to take in another rescue boat called the Lifeline which was carrying 234 people after a similar deal was struck with EU states to take the migrants in.
That incident came just two weeks after another crisis involving the Aquarius which had been had been turned away by Italy and Malta with 630 people on board but was eventually offered safe haven by Spain's new Socialist government.
But this time, Madrid was reluctant to repeat the offer amid strong criticism over its welcoming stance from the conservative opposition and the regional Socialist government in Andalusia less than a year from regional and European Union elections.
For migrants, the southern Andalusia region is the main gateway into Spain, and the region has struggled to cope with an influx in migrant arrivals.
Speaking to AFP on Monday, a Spanish government source said Madrid did not intend to repeat the gesture by allowing the Aquarius to dock in the eastern port of Valencia, saying it was “not the safest port” for the ship.
Northeast region Catalonia responded by offering to let the Aquarius migrant ship at one of its ports, seemingly setting the stage for a clash with Madrid.
In a Twitter message, Catalonia's separatist president Quim Torra said he had asked the ports authority in the northeastern region to let the Aquarius dock at one of three seaside resorts: Palamos, Vilanova or Sant Carles de la Rapita.
“Catalonia will always be a welcoming land,” he said.
While the overall number of migrants reaching Europe by sea is down from the peak in 2015, Spain has seen a steady increase in sea arrivals that began more than a year ago and has surged in recent months.
The country has overtaken Italy as a destination for migrants arriving by sea after a crackdown by Libyan authorities made it more difficult for migrants to reach Italian shores.
Over 25,000 people have arrived by sea in Spain so far this year, nearly three times more than the same period last year, International Organization for Migration figures show.
Since taking in the Aquarius in June, Spain has opened its ports three more times to NGO ships carrying migrants rescued off Libya.