A Malaysian military officer whose legal case prompted outrage after he left New Zealand under the protection of diplomatic immunity was sentenced Thursday to nine months of home detention after pleading guilty to indecent assault.

New Zealand Judge David Collins said Muhammad Rizalman Ismail will serve the sentence in a Wellington rental home before being deported back to Malaysia.

Rizalman was arrested in May 2014 after he broke into the home of a 21-year-old woman, entered her bedroom wearing nothing but a shirt and struggled with her before she escaped and called police.

He returned to Malaysia soon after under diplomatic protection. New Zealand initially blamed Malaysia but then conceded its own officials may have helped facilitate Rizalman's departure.

He was extradited back to New Zealand in November 2014.

In a written decision, Judge Collins said Rizalman, 39, moved to New Zealand with his wife and three children after being appointed to his post at the Malaysian Embassy in 2013. The next year, the judge said, Rizalman began acting in strange ways, including purchasing synthetic marijuana and hitting on women.

In May, he followed Tania Billingsley home after he thought she smiled at him, the judge said. He waited outside her home for more than half an hour, defecating and then removing his pants and underpants before breaking in and entering her bedroom, where she was watching a movie, according to the judge.

"She leapt from her bed and screamed at you to get out," Collins wrote. "You then approached Ms. Billingsley and grabbed her shoulders."

The judge said Billingsley managed to push Rizalman aside and grab a knife from the kitchen.

The judge said Rizalman had no previous record and had written Billingsley a letter of apology. But he added that he was struck by Rizalman's lack of insight into his offending and its impact on Billingsley, who continues to be traumatized by the incident.

Rizalman was ordered to pay Billingsley an undisclosed amount for reparations.

The Associated Press does not typically identify victims in sexual or indecent assault cases, but Billingsley decided to identify herself in July 2014 and to speak out publicly, saying she felt frustrated and angry Rizalman had been able to leave.