The Federal Constitutional Court in the southwestern city of Karlsruhe said denying gays and lesbians in civil partnerships tax breaks extended to married people violated their civil rights.
The scarlet-robed judges said their ruling applied retroactively to August 1, 2001, the day on which Germany created such so-called registered partnerships – a status that falls short of marriage under the law.
The court said that gay and lesbian couples must immediately be granted the same tax benefits as heterosexual married couples because there were no "substantial grounds for unequal treatment."
It said a failure to do so contravened the equal treatment clause of Germany's Basic Law and ordered parliament to pass new legislation.
All parties in the Bundestag lower house had expressed their support for such a policy with the exception of Chancellor Angela Merkel's conservative Christian Union bloc.
The ruling marks a setback for Merkel's party with less than four months to go until a general election.
"What a joy – another step toward equality," Katrin Goering-Eckardt, a candidate for chancellor from the opposition Greens, tweeted in reaction to the decision. "And another embarrassment for the Merkel government."
Merkel said in a newspaper interview in December that she did not favour putting gay couples on the same tax footing as heterosexual ones because the constitution "sees marriage as directly linked to the family and both are under special protection of the state".
Married couples who have a big difference in salary, or where one partner does not work, benefit from having their incomes pooled in the calculation of their individual tax bills.
Same-sex couples had been denied such a tax break and the ruling will mean that the German tax authorities will have to pay out millions to gays and lesbians in civil unions who overpaid.
The decision followed a ruling in February which found that gays in a civil partnership should be allowed to adopt their partners' adopted children.
Gay couples are still forbidden from adopting children together in Germany. Neighbouring France legalised same-sex marriage last month amid a bitter controversy over the issue, making it the 14th country to do so and the seventh in the European Union.
Nine US states as well as the capital Washington have also granted gays the right to marry.