WARSAW, Poland — Poland cannot extradite filmmaker Roman Polanski to the United States on a charge that he had sex with a minor nearly four decades ago, a judge ruled Friday, a decision that could finally close the case in the country where the Oscar-winning director grew up and still makes movies.

“I can breathe now with relief,” Polanski 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.”

The Polish prosecutor who argued for extradition on behalf of the United States did not immediately say whether there would be an appeal. The victim in the case has repeatedly called for the prosecution to be dropped.

Judge Dariusz Mazur, who ruled in Krakow, where Polanski has his apartment, said the case was complicated but an extradition would violate Polanski’s human rights because he could be held in confinement while it was happening.

Polanski’s attorneys contended he had already served prison time under a plea-bargain deal with a Los Angeles judge.

Polanski was initially charged with 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 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 afterward he would ask Polanski to agree to a “voluntary deportation.” Polanski fled from the United States on Feb. 1, 1978, the day he was scheduled to be sentenced.