Roman Polanski has beaten a US attempt to extradite him as a Polish judge ruled that the nation's law forbids sending the film-maker back to the States, where he pleaded guilty nearly four decades ago to having sex with a minor.

"I can breathe now with relief," the Oscar-winning director told reporters in Krakow, where the case was heard.

"I pleaded guilty. I went to prison. I have done my penalty. The case is closed," said the 83-year old director, who appeared thin and exhausted.

Polanski also beat a US attempt to extradite him from Switzerland more than a decade ago.

The decision could finally close the case in Polanski's favour. The Polish prosecutor who argued the case for extradition on behalf of the US did not immediately say whether there would be an appeal.

Judge Dariusz Mazur said the case was very complicated but an extradition procedure would violate the human rights of the elderly Polanski because he could be sentenced to confinement.

"I find no rational answer to the question: what is the real point of the U.S. extradition request?" said Judge Mazur, who spent more than two hours explaining his reasoning to the court.

The judge said Polanski served his punishment in confinement in the US, and later for 10 months - partly under house arrest - in Switzerland in 2009-10 when the US unsuccessfully sought his extradition there.

US judges and prosecutors violated legal procedures, broke the plea bargain in 1977, denied Polanski the right to proper defence and appeared biased, the judge found.

Polanski was not in court for the ruling, but followed live TV coverage of the proceedings.

"I am glad that I have trusted Poland's justice system," he told reporters.

"Listening to the court today I was really moved because I had not imagined the judge would know the case in such detail, with all the dates quoted correctly. There was not one mistake."

Polanski's lawyers had argued that the US request was legally flawed and contended he had already served prison time under a plea bargain deal with a Los Angeles judge.

Polanski was initially charged on six felony counts, including rape by use of drugs, but was allowed to plead guilty in 1977 to one count of unlawful sexual intercourse with a 13-year-old girl during a photo shoot in Los Angeles.

In exchange, the judge agreed to drop the other charges and sentenced him to prison for a 90-day psychiatric evaluation. Polanski was released after 42 days by an evaluator who deemed him mentally sound and unlikely to offend again.

The California judge then said he was going to send Polanski back to prison for the remainder of the 90 days and that afterwards he would ask Polanski to agree to a "voluntary deportation". Polanski fled from the US on February 1 1978, the day he was scheduled to be sentenced to the additional time.

Judge Mazur said Polanski had reason to believe he would be put in prison for a longer time.

A lawyer representing Samantha Geimer, the victim in the case, said the ruling should close the case.

"Both the judicial systems of Poland and Switzerland are able to do what the judicial system of the United States seems unable to do, and that is put the matter behind us," said Lawrence Silver.

Ms Geimer has publicly identified herself in court filings, interviews and a memoir, and has repeatedly called for the case against Polanski to be closed.

Polanski is a celebrity in Poland, and public opinion in his childhood country has been mostly in his favour. He won an Academy Award for best director for his 2002 film The Pianist and was nominated for 1974's Chinatown and 1979's Tess.

His movements are restricted by an Interpol warrant in effect in 188 countries, but he has avoided extradition by remaining only in France, Poland and Switzerland.

PA Media