The Luxembourg-based European Court of Justice heard the case at the request of a Munich court seeking advice on whether the refusal in such circumstances broke EU discrimination rules.
The case was initiated by Tadao Maruko, who was in a life partnership under German law with a designer of theatrical costumes who died in 2005.
Following the partner's death, Tadao Maruko brought the case to the German court after the institution that manages pensions for German theatre workers and their survivors rejected his application for his partner's pension.
"The court rules that the refusal to grant the survivor's pension to life partners constitutes direct discrimination on grounds of sexual orientation, if surviving spouses and surviving life partners are in a comparable situation as regards that pension," it said in its decision.
European Commission welcomed the decision. "It strengthens the principle of non-discrimination on the grounds of sexual orientation and further specifies the rights of registered homosexual partners in the area of employment and occupation," said commission spokeswoman Katharina Von Schnurbein said.
Not all EU countries have laws giving specific legal status and rights to same-sex couples.
The EU court said that it was ultimately up to national EU courts to decide whether a surviving partner in a same-sex couple was in a situation comparable to that of a spouse entitled to the survivor's pension.