From 1949 to 1969, under a law inherited from the Nazi regime, about 50,000 men in West Germany were convicted of homosexuality. Many served time in prison.

Although the law — known as Paragraph 175 for the section it was part of in the country’s Criminal Code — was eased in 1969, it stayed on the books. As a result, another 3,500 men were convicted before the law was finally rescinded in 1994, four years after the reunification of Germany. Even then, the convictions stayed on the men’s criminal records. (Communist East Germany decriminalized homosexuality in 1968.)

The German government on Wednesday announced that it would finally correct what it called a longstanding injustice.

The justice minister, Heiko Maas, said the government would put forward legislation that would overturn the convictions and allow for financial compensation to the men who suffered under the legislation. Mr. Maas said the decision was reached after a study by the federal government’s anti-discrimination agency concluded there was no reason the men should not be legally rehabilitated.