A fed-up judge in Iowa tossed charges against a man who confessed to sexually assaulting a minor — because the prosecutor in the case showed up to court drunk.

Clarke County attorney Michelle Rivera was nabbed on Oct. 18 for her tipsy appearance in an Osceola courtroom — just moments before the defendant was about to plead guilty and be sentenced in the case.

As a result, Rivera missed a crucial legal deadline requiring the man to be tried within one year of his arraignment.

The lush of a lawyer was arrested for the second time last week after allegedly driving to the courthouse drunk, WHO TV reported. She was also charged with child endangerment for driving her daughter to daycare minutes before someone called 911 about her erratic driving.

In a new ruling, Judge Marti Mertz said enough was enough — and that Rivera’s no-show at a recent hearing in the sex assault case “was the finale following unexplained periods of inactivity and lack of responsiveness” since the man’s arrest more than a year ago.

The defendant was initially charged with sex assault and telephone dissemination of obscene material to a minor — and admitted to engaging in a sex act with a minor in August 2017, investigators said.

But defense lawyer Marshall Orsini sought to have the charges thrown out because he hadn’t been tried within a year.

“If the defendant is not put on trial [and] is not tried within a year, you have the potential to have that case dismissed, and that’s what happened here,” Orsini told KCCI 13.

Rivera, a county attorney since 2011, pleaded guilty to being drunk in court and was fined $65.

The status of her most recent arrest isn’t clear.