MUNICH (AP) — Retired U.S. autoworker John Demjanjuk was convicted of thousands of counts of acting as an accessory to murder at a Nazi death camp and sentenced on Thursday to five years in prison, a groundbreaking verdict that closed one chapter in a decades-long legal battle.

Judges ordered him released pending appeal, on the ground that he did not pose a flight risk.

Demjanjuk was found guilty of 28,060 counts of being an accessory to murder, one for each person who died during the time he was ruled to have been a guard at the Sobibor camp in Nazi-occupied Poland.

Presiding Judge Ralph Alt said the 91-year-old was a piece of the Nazis’ “machinery of destruction.”

“The court is convinced that the defendant … served as a guard at Sobibor from 27 March 1943 to mid-September 1943,” Alt said, closing a trial that lasted nearly 18 months.

Demjanjuk sat in a wheelchair in front of the judges as they announced their verdict, but showed no reaction. He has denied the charges, but declined the opportunity to make a final statement to the court.

Demjanjuk’s son, John Demjanjuk Jr., asserted that “the Germans have built a house of cards and it will not stand for long.”

Alt later ordered that Demjanjuk be freed during his appeal — a process that is likely to take six months or more — though it wasn’t clear when exactly he would leave the prison.

Such a release is not unusual in Germany, and Alt said Demjanjuk did not pose a flight risk because of his advanced age, poor health and the fact that the defendant, deported from the U.S. two years ago, is stateless. The costs of Demjanjuk’s two lawyers are being shouldered by German authorities, who routinely pay the legal costs of low-income defendants.

Alt told The Associated Press that meant there were “no grounds” to hold him. “It’s the law, and so it’s justice,” he added. “I say he’s guilty, but it’s not a final verdict.”

Demjanjuk is not allowed to leave Germany. Alt said that the issue of whether or not Demjanjuk died in a German jail had “nothing to do” with the decision.

Defense attorney Guenther Maull said it wasn’t yet clear where Demjanjuk would go once he is freed, but he was likely to live with members of the Ukrainian community in Munich. The court noted that Demjanjuk, who suffers from a variety of ailments, needs daily medical attention.

Charges of accessory to murder carry a maximum term of 15 years in Germany, which does not allow consecutive sentences for multiple counts of the same crime.

There was no evidence that Demjanjuk committed a specific crime. The prosecution was based on the theory that if Demjanjuk was at the camp, he was a participant in the killing — the first time such a legal argument has been made in German courts.

Thomas Walther, who led the investigation that prompted Germany to prosecute Demjanjuk, said before the verdict that other low-ranking Nazi helpers could now face prosecution.

“It could be very soon that more are brought to the table,” he said. “This case is a door-opener.”

Integral to the prosecution’s case was an SS identity card that allegedly shows a picture of a young Demjanjuk, and indicates he trained at the SS Trawniki camp and was posted to Sobibor.

Though court experts said the card appears genuine, the defense maintains it is a fake produced by the Soviet KGB.

The U.S. Department of Justice’s Office of Special Investigations also has said the card is genuine, but documents unearthed by The Associated Press indicate that the FBI at one time had doubts similar to those aired by Demjanjuk’s defense about the evidence — though the material was never turned over to them.

Rudolf Salomon Cortissos, whose mother was gassed at Sobibor along with thousands of other Dutch Jews, cried softly in a back row of the courtroom, wiping his tears with a white handkerchief, as Alt somberly read out the names of the brothers, sisters and parents of people who joined the trial as co-plaintiffs, as allowed under German law.

“It’s very emotional — it doesn’t happen every day,” he said, adding that he was happy with the verdict and sentence. “For me it is satisfying,” he said.

Ukrainian-born Demjanjuk has been stripped of his U.S. citizenship and has been in custody in Germany since his deportation two years ago.

Cornelius Nestler, a lawyer for co-plaintiffs, said he likely would serve three years at most, given the time he has already spent in German custody.

But he said he, too, was satisfied with the sentence, which came close to prosecutors’ call for a six-year term. That call took into account the defendant’s age, and time he already served in Israel in the 1980s.

The verdict won’t entirely end more than 30 years of legal wrangling. Along with the German appeal, and legal proceedings continue in the United States.

The Simon Wiesenthal Center’s chief Nazi hunter, Efraim Zuroff, called the conviction “a very important victory for justice.”

“The verdict sends a very powerful message that, even many years after the crimes of the Holocaust the perpetrators can be brought to justice,” he said by telephone from Jerusalem. “We’re hopeful that this verdict will pave the way for additional prosecutions in Germany.”

Zuroff said later, however, that he was “very surprised” by the decision to free Demjanjuk pending the appeal.

“We don’t think that that’s appropriate given the heinous nature of his crimes,” he said.

In the 1980s, Demjanjuk stood trial in Israel after he was accused of being the notoriously brutal guard “Ivan the Terrible” at the Treblinka extermination camp. He was convicted, sentenced to death — then freed when an Israeli court overturned the ruling, saying the evidence showed he was the victim of mistaken identity.

Demjanjuk maintains he was a victim of the Nazis — first wounded as a Soviet soldier fighting German forces, then captured and held as a prisoner of war under brutal conditions before joining the Vlasov Army, a force of anti-communist Soviet POWs and others that was formed to fight with the Germans against the Soviets in the final months of the war.

Demjanjuk’s son said he was relieved at the decision to free his father “because he has never deserved to sit in prison for one minute.”

But “after everything that he’s gone through, it is hard to use a word like happy in any context,” he said by phone from Cleveland, Ohio.

Prosecutors said that after his capture, the evidence shows Demjanjuk agreed to serve the German SS and was posted to Sobibor in Nazi-occupied Poland.

Demjanjuk was accused of having served as a “wachmann,” a guard, the lowest rank of the “Hilfswillige” volunteers who were subordinate to German SS men.

In a 1985 report, the FBI’s Cleveland field office concluded that: “Justice is ill-served in the prosecution of an American citizen on evidence which is not only normally inadmissible in a court of law but based on evidence and allegations quite likely fabricated by the KGB.”

That revelation has led to new court action in the U.S., with a District Court judge in Cleveland on Tuesday agreeing to appoint a public defender to represent Demjanjuk there, raising the prospect of renewing the decades-old case.

___

Andrea M. Jarach in Munich and Geir Moulson in Berlin contributed to this report.