Spanish prime minister Pedro Sanchez said his country is prepared to be part of a European response to the plight of a German-operated migrant aid ship - but did not specify whether it will allow the vessel to dock.
Earlier this month, Spain took in 630 migrants from the French aid ship Aquarius after Malta and Italy refused it access.
A similar situation has now arisen with a ship operated by the German aid group Mission Lifeline, which has been stuck off Malta since Thursday with 234 migrants aboard.
Mr Sanchez was asked during a visit to Berlin whether Spain would offer safe harbour.
He replied that Spain would be part of the "common answer", but added that the solution "has to be European, it has to be from various countries".
Meanwhile, the leader of Malta said the island nation is working to resolve the case of a rescue ship.
Prime Minister Joseph Muscat said Malta aims "to prevent escalation into humanitarian crisis" by sharing the responsibility with other fellow EU nations.
The statement also said that Malta planned to investigate the captain of the Lifeline, run by a German non-governmental agency, nothing that he had ignored instructions.
The ship has been stranded for days since Italy's populist interior minister refused to allow it access to ports.