The new Spanish government has stepped in to end a standoff on the high seas, agreeing to take in more than 600 migrants picked up by a rescue ship in the Mediterranean.