The ship sank in the Mediterranean Sea between Spain and Algeria following an explosion in the engine room, officials said.