GENEVA, Sept 8 (Reuters) - A European and African deal to stem the flow of migrants coming through Libya to Europe fails to tackle the abuses they face, the top U.N. human rights official wrote on Friday.

The 28-nation European Union has long struggled to reach a coherent answer to the influx of migrants fleeing war, poverty and political upheaval in the Middle East and Africa, and the crisis is testing cooperation between member states.

On Aug. 28, the leaders of France, Germany, Italy, Spain, Chad, Niger and Libya agreed a plan to tackle illegal human trafficking and support nations struggling to contain the flow of people across the desert and Mediterranean sea.

U.N. High Commissioner for Human Rights Zeid Ra'ad al-Hussein said it was significant that the agreement they struck in Paris recognised that a comprehensive response was needed.

"But it is very thin on the protection of the human rights of migrants inside Libya and on the boats, and silent on the urgent need for alternatives to the arbitrary detention of vulnerable people," he wrote in an article published by the United Nations.

Zeid's office published a report last December on abuses faced by migrants in detention centres in Libya, "but memories are short when facts are inconvenient", he wrote.

Since then the situation had worsened, with far too many allegations to verify and reports of bodies "in the desert, in the forest, on the beaches". Libya's morgues were overflowing, he said.

Apart from the families awaiting word from missing relatives, hardly anybody seemed to care, Zeid wrote.

The EU faces a moral and legal dilemma because it relies on cooperation with Libyan coastguards and plays down their abuses, which include shooting at aid workers trying to rescue migrants, Zeid said.

"A coastguard that sometimes rescues migrants in distress - but sometimes chooses not to. Like the militias onshore, coastguards also sometimes beat, rob and even shoot the migrants they intercept," he said.

Zeid said he agreed with a letter to European leaders from Joanne Liu, the head of Medecins Sans Frontieres, a charity that has sent aid workers to rescue migrants.

The letter, entitled "European governments are feeding the business of suffering", asked: "Is allowing people to be pushed into rape, torture and slavery via criminal pay-offs a price European governments are willing to pay"

"I fully support her analysis, and share her disgust at this situation," Zeid wrote.

(Reporting by Tom Miles; Editing by Alison Williams) ((tom.miles@thomsonreuters.com; +41 58 306 2006; Reuters Messaging: tom.miles.reuters.com@reuters.net))