A Montana woman accused of breaking into her ex-boyfriend’s home with a machete — and then raping him — was sentenced this week to 20 years in a state psychiatric hospital, according to a new report.

Samantha Ray Mears, 20, was charged in June 2018 with entering her former beau’s home while he was out, local outlet KPAX reported.

When he returned, she went up to him from behind, wielding a machete, according to court documents obtained by the outlet.

Mears demanded that her ex get in his birthday suit and get on the bed, the documents say. He reportedly told authorities he didn’t feel he could escape without being hurt by Mears.

Then, according to the documents, Mears removed her pants, crawled on top of the man — and had sex with him. She’s also accused of biting him on the arm as they had intercourse.

Afterward, Mears — still armed with the machete — ripped a piece of trim off the wall and intentionally urinated on her former flame’s bed, according to the documents.

She initially was charged with aggravated burglary, assault with a deadly weapon and unlawful restraint, among other counts, the station reported.

She was sentenced Tuesday to the custody of the state Department of Public Health and Human Services for the offense of sexual intercourse without consent — as the world “rape” is not used in Montana code.

The judge ruled that Mears be placed in “an appropriate mental health facility.”

She was also designated as a Tier 2 sex offender and required to complete appropriate treatment and counseling, according to the station.

Mears suffers from a “mental disease or defect,” according to the court documents — and she was given the maximum penalty allowed by Montana law under those circumstances.