Migrants are rescued by staff members of the MV Aquarius, a search and rescue ship run in partnership between SOS Mediterranee and Medecins Sans Frontieres in the central Mediterranean Sea, June 10, 2018. Picture taken June 10, 2018. Karpov/handout via REUTERS

MADRID (Reuters) - Spain offered on Monday to take in a rescue ship that is drifting in the Mediterranean sea with 629 migrants stranded on board after Italy and Malta refused to let it dock.

The Aquarius picked up the migrants from inflatable boats and rafts off the coast of Libya at the weekend, and the United Nations refugee agency said on Monday it was running out of provisions.

Spain’s Prime Minister Pedro Sanchez, who took office just over a week ago, has given instructions for the boat to be admitted to the eastern port of Valencia, his office said in a statement.

“It is our duty to help avoid a humanitarian catastrophe and offer a safe port to these people, to comply with our human rights obligations,” Sanchez’s office said.

The Aquarius took the migrants, including 123 unaccompanied minors, 11 other children and seven pregnant women, toward Italy, but the country’s new, far-right Interior Minister barred it from docking and said it should go to Malta.

Malta refused to take the ship, saying it was Italy’s responsibility as the rescue was overseen by the Italian coastguard. The tiny island says it already accepts proportionately more refugees than Italy.

Sanchez, a Socialist who toppled his conservative predecessor with a no-confidence vote after a corruption scandal, made his offer after the mayors of Valencia and Barcelona both offered to take the boat in at their ports.