The law passed the Bundestag lower house with the support of all five parties in parliament and marked the culmination of a decades-long fight for justice on behalf of those who turned their backs on Hitler's forces.
"It took far too long," deputy Wolfgang Wieland of the Green party told the chamber, apologising to a campaigner for the bill, 87-year-old Ludwig Baumann, who attended the vote at the Reichstag parliament building.
"Many of his comrades are dead and never lived to witness their rehabilitation," Wieland told deputies.
Just a week after solemn commemorations to mark the start of World War II on September 1, 1939 with the German invasion of Poland, MPs finally closed the book on what campaigners called an enduring injustice.
"To turn one's back on such a war - was that not the better choice than to follow orders to the end?" Wieland said. "That is the decisive question."
Nazi military tribunals sentenced some 30,000 people to death for desertion or treason during the war, of whom 20,000 were executed, according to historians whose work was cited in the bill.
Around 100,000 men were sentenced to prison. The victims were not only Germans but also citizens of Austria, Denmark, Norway, Romania and Luxembourg. All who survived had a criminal record, often could not find jobs in the postwar years and even faced death threats for their "betrayal of the Fatherland."
In 2002, parliament wiped the convictions of conscientious objectors and deserters such as Baumann from the books but not those of "wartime traitors." These included soldiers, officers and some civilians accused of crimes such as political resistance - even making critical remarks about the Nazis made in private - or helping persecuted Jews.
Since then, there had been repeated attempts to erase the convictions but no clear majority in parliament. Conservatives had long opposed an across-the-board rehabilitation, calling for a case-by-case review to determine whether there had been "legitimate" convictions.
However, a Justice Ministry review conducted by a former constitutional court judge found that the Nazis' treason law dating from 1934 was a clear instrument of repression, so vague as to be open to capricious rulings. That report eliminated the remaining opposition to the bill.
Few if any of those convicted but not executed are still alive today. Baumann founded the German Federation of Victims of National Socialist Military Justice in 1990 and had since then fought an uphill battle to see the records wiped clean.
He narrowly escaped execution for deserting his Wehrmacht company in Bordeaux in 1942 but he endured torture after his capture and was ostracised by his fellow Germans for decades after World War II.
"My dream of seeing all the victims of Nazi justice rehabilitated will have been fulfilled," Baumann said ahead of the vote. "But I will be sad because I will not be able to drink a toast to this success with any of my comrades in suffering."
In Austria, campaigners are still seeking the annulment of the verdicts of the Nazis' military tribunals and the rapid settlement of deserters' claims for aid as victims as well as a national memorial for the deserters. Such a memorial was erected in Cologne, western Germany last week.