Asylum seekers must not be subjected to psychological tests to determine whether they are homosexual, EU's top court has ruled.
Tests to determine sexual orientation are controversial, but are sometimes used when assessing asylum claims.
The European Court of Justice (ECJ) ruling is binding in all 28 EU states.
The ECJ case relates to a Nigerian man who submitted an asylum application in Hungary in April 2015. He feared persecution in Nigeria for being gay.
Hundreds of homosexuals fearing persecution in Africa, the Middle East and Chechnya have sought asylum in the EU, the EU Agency for Fundamental Rights reports.
The Nigerian's claim was rejected after a psychologist's report failed to confirm his homosexuality.
A court in Szeged, Hungary, must now reconsider his case in light of the ECJ ruling.
What about similar gay rights cases?
In December 2014 the ECJ ruled on a similar case in the Netherlands and found that sexuality tests violated asylum seekers' human rights.
In the new ruling, the ECJ said "certain forms of expert reports may prove useful" in such cases, but added that such reports interfered with a person's privacy. Authorities must also determine the reliability of a claimant's statements, the judges said.
In 2013 the ECJ ruled that asylum could be granted in cases where people were actually jailed for homosexuality in their home country.
Homosexual acts are illegal in most African countries, including key Western allies such as Uganda, Nigeria, Kenya and Botswana.
What happens next in this case?
The Hungarian court cannot appeal against the ECJ ruling, so the Nigerian man - identified only as "F" - now has a stronger claim for asylum.
The ruling means that EU countries now have no legal right to impose psychological tests to determine an asylum seeker's sexuality.
What did Hungary originally decide?
The ECJ says Hungarian officials had not found F's statements to be fundamentally contradictory, but had still concluded that F lacked credibility.
Their decision was based on a psychologist's report, which included:
- An exploratory examination
- An examination of personality
- Personality tests (Draw-A-Person-In-The-Rain, Rorschach and Szondi tests)
The report "concluded that it was not possible to confirm F's assertion relating to his sexual orientation".
Psychologists have long held that personality traits can be revealed by tests such as "draw a person in the rain" and the Rorschach test, which relies on an individual's interpretation of inkblots.
What sort of tests were at issue here?
They were quite general psychological tests, aimed at identifying F's personality type and emotional characteristics.
F said the tests had violated his fundamental rights and they had not provided any assessment of "the plausibility of his sexual orientation", the ECJ said.
It also said any indication of sexual orientation provided by such tests could only be "approximate in nature". They were "of only limited interest for the purpose of assessing the statements of an applicant for international protection".
In 2010 the EU's Fundamental Rights Agency condemned the Czech authorities for using "phallometric" sexual arousal tests on some asylum seekers to determine whether they were gay. Czech officials said the tests had been used in fewer than 10 cases, with the individuals' consent.
The Hungarian court handling F's case quoted him as saying that he had not undergone any physical examination and had not been required to view pornographic photographs or videos.
Is Hungary a special case?
No - other EU countries also conduct psychological tests on asylum seekers, to assess whether their statements can be believed.
The UK Home Office has detailed guidance on asylum claims based on sexual orientation.
The gay rights group ILGA-Europe says there is a huge diversity in the EU in the way asylum authorities assess someone's sexual orientation.
In F's case tests were imposed on him - unlike the Dutch asylum case of 2014, when several Africans offered evidence of their homosexuality.
In the Dutch case, the ECJ ruled that it was wrong to conduct "detailed questioning as to the sexual practices of an applicant for asylum".
F's asylum claim in 2015 came during a migrant crisis for Hungary. The country faced a huge influx of migrants - many of them Syrians, Iraqis and Afghans fleeing war. Most of them moved to Germany, via Austria, and Hungary then built a formidable border fence to keep migrants out.