VALLETTA  -  The Aquarius rescue ship arrived in Malta on Wednesday after EU countries thrashed out a deal to take in the 141 migrants onboard, defusing another diplomatic standoff in the Mediterranean.

The ship reached the Maltese port of Valletta shortly after 2 pm (1200 GMT), according to an AFP reporter there. The Aquarius had rescued the migrants off the coast of Libya in two separate missions last Friday, only for Italy and Malta to refuse access to their ports.

The standoff was a repeat of that seen in June when the vessel was at the centre of a heated diplomatic crisis between European governments.

Stranded with 630 people onboard after Rome and Valletta turned it away, the Aquarius had finally been allowed to dock in Spain.

On Tuesday, France, Germany, Luxembourg, Portugal and Spain agreed to take in its latest passengers, along with 114 others who arrived in Malta on Monday. The agreement is the fifth of its kind between Western European governments since June when Italy - until now the main landing point for rescue boats - began turning them away.

Italy's new populist government says it has had enough of migrant arrivals, having taken in 700,000 people since 2013.

Far-right Interior Minister Matteo Salvini has vowed that the Aquarius will "never see an Italian port" again, though the Italian coastguard continues to rescue migrants. NGOs say they have a moral obligation to rescue people making the perilous crossing, who could otherwise join the estimated 1,500 killed en route this year alone. Most of the 114 people onboard the Aquarius are from Somalia or Eritrea, and many of them are unaccompanied children. Aloys Vimard, a coordinator with Doctors Without Borders (MSF) onboard, told AFP that the passengers were exhausted and in many cases mentally scarred from harrowing journeys.

One 13-year-old Somali boy had seen his parents killed in front of him. After finally making it to Libya he suffered horrendous abuse, "tortured for months with electric shocks".

Malta's government said the military would help disembark the passengers, and that health authorities, immigration police and welfare officials would be at the scene. The migrants will be medically screened and then taken to a reception centre where officials will start the process of distributing them between the five other European countries.

Spain has offered to take 60 people, Germany up to 50 and Portugal 30. France has said it will accept 60 from the Aquarius and another rescue boat that arrived earlier in Malta. Luxembourg said it would take in five of the migrants.

SOS Mediterranee praised the agreement, saying it "shared out responsibilities in a coordinated European response". The UN's refugee agency, the UNHCR, also hailed the deal but warned that Europe needed to come up with more permanent solutions.

"The situation should never have come to this in the first place," said UN High Commissioner for Refugees Filippo Grandi. The UN called for an agreement "that provides clarity and predictability on where boats carrying rescued passengers can dock". "This is essential if further such situations are to be avoided," it added.

Grandi said of countries that refused to take in migrants that it was "wrong, dangerous and immoral to keep rescue ships wandering the Mediterranean while governments compete on who can take the least responsibility".