BRUSSELS — Giuseppe Dura came upon 51 African migrants frantically waving from a stranded boat 180 kilometers off the coast of Libya last Friday. But when Dura, the Spanish captain of a fishing trawler, radioed Spain for help on a distress channel, he told reporters, he was shocked to receive no reply.

Fearing that the migrants could drown, Dura said, he and the other nine crew members of the Francisco Catalina decided to take the group on board, including a pregnant woman and several children.

Little did he foresee, he said, that the lifesaving move would result in a diplomatic standoff involving Spain, Malta, Libya and the European Union that left the migrants, the 39-year-old captain and the crew stranded for six days on the open sea with nowhere to go.

"I convened a meeting with the crew, and we decided we could not leave the immigrants alone in their boat, without any lights and adequate shelter or provisions," Dura told The Times of Malta. "So we took them on board."

"I knew there would be some problems, but I was sure these would be resolved in a day at most," he said. "Little did I think I would be raising an international issue on such a scale simply because I rescued people from almost certain death."

The lack of any response to the distress call seemed to embody an increasing hostility toward migrants across parts of Europe, an attitude that became clearer only as the Africans spent days at sea.

But late Wednesday, a plan began to take form to end the migrants' ordeal. The framework, still being hammered out Thursday, would divide the migrants - the majority of whom are Eritrean - by dividing them among Spain, Libya, Malta, Italy and Andorra.

Under the plan being worked on by the European Union, the migrants would be removed from the trawler and taken to Malta, where 8 would stay. The rest would be sent on two Spanish Hercules C-130 transport planes, with 15 ending up in Spain, 10 in Libya, 10 in Italy and 8 in Andorra.

A pregnant woman and another woman and her child who were transported earlier to Malta to receive medical attention will remain on the island indefinitely, the Maltese authorities said. Five Moroccans will be repatriated at the EU's expense.

Upon learning of the ship, Malta said it was up to Spain or Libya to handle the problem, since the ship was registered in Spain and the migrants were found in Libya's search-and-rescue zone. But Spain insisted it had no legal obligation to provide refuge, and that either Malta or Libya had to let the migrants land.

On Thursday, Malta's interior minister, Tonio Borg, was unrepentant, saying that the crisis had been a test case for whether the EU was willing to share the burden of a migration problem that had reached a crisis point.

Dura told reporters that he immediately sent a distress signal to the Spanish authorities but that no one replied. Fearing that the migrants would die on the open sea, he met with his crew, who unanimously decided to grant the migrants refuge. That decision had the unintended consequence of making Spain legally responsible for the migrants by placing them on a Spanish-registered vessel.

The migrants told The Times of Malta that they left Libya on July 10. Amanisi, a 24-year-old Eritrean migrant who declined to give his last name, told reporters that he had left Eritrea a year ago, went to Ethiopia, then to Sudan and later to Libya. There, he joined a group of migrants, who found a smuggler who asked them each for $1,200 to pay for a boat equipped with a small outboard engine. The migrants said they were told that it would take them at most three days to reach Italy.

But the engine on the overloaded boat stalled soon after leaving Libya, and the boat drifted to sea, prompting the panicked migrants to try desperately to get the attention of the Spanish shrimp trawler fishing nearby.

"I decided to call the Spanish rescue center from my mobile phone to inform them about the issue, and diplomatic wrangling started," Dura told The Times of Malta. On Saturday night, the trawler asked to enter Malta but permission was refused.

Natalino Fenech, a journalist with The Times of Malta who boarded the stranded trawler, said the boat the immigrants left on was tied behind, and was littered with pieces of bread and biscuits, shoes and clothing. He said the heat and stench on the trawler were unbearable. "It was hard to believe that these people could still be on their feet after having spent so much time at sea in those conditions," Fenech said.

Asked why he had fled Africa, Amanisi, the Eritrean migrant, told Fenech he had no future there.

"I left Eritrea because of political and religious oppression," he said. "Men aged 20 to 40 have to serve in the army, which is a near-certain death. Eritrea and Ethiopia are in constant conflict and the wars are claiming many lives. I did not want my life to end that way."

Paul Pace, head of the Jesuit Refugee service in Malta, said the standoff showed that EU countries were making border issues a priority over human rights. "The conditions aboard the ship were cramped and appalling, and it is hard to understand why these people were not granted shelter," he said in an interview. "It is very worrying that the rights of human beings are being treated as secondary."

The second-in-charge aboard the Spanish ship, Bautista Molina, in an interview with the newspaper El Pais reported by The Associated Press, said, "We did what we had to do. We are exhausted, but our conscience is clear."