(CNN) -

Malaysia says it will send back to New Zealand an envoy who used diplomatic immunity to flee a sex charge there, defusing a messy wrangle between the nations.

Malaysia's government released a statement Wednesday saying it would return Second Warrant Officer Muhammad Rizalman Ismail to New Zealand "to cooperate fully and assist" authorities in their investigation into allegations against him

Ismail, 38, faces charges of burglary and assault with intent to commit rape, relating to an alleged attack in Wellington on May 9, according to officials in both countries.

New Zealand Foreign Minister Murray McCully welcomed the news of Ismail's impending return, saying in a statement that it underlined the "good faith and integrity" with which Malaysia had approached the case.

Ismail was working as a defense staff assistant at Malaysia's High Commission in Wellington when he allegedly stalked a 21-year-old woman and attacked her in her home.

He was apprehended by police and appeared in court the next day, but returned to Malaysia with his family on May 22, Malaysia's Ministry of Foreign Affairs said in a statement.

The case caused an outcry when it was reported in the New Zealand media, with Prime Minister John Key telling reporters it was his country's "very strong preference" that the man face justice there, rather than in Malaysia.

But it later emerged that while at a formal level New Zealand had pressed Malaysia to waive Ismail's diplomatic immunity, Malaysian officials were under the impression after informal discussions that the New Zealand government was comfortable with him returning home to face justice, CNN affiliate TVNZ reported.

McCully apologized Wednesday for his ministry's handling of the case, TVNZ reported.

"It is now clear to me that officials engaged in informal communications over what is a complex case, in a manner that would have been ambiguous to the Malaysian government," he said in a statement. "I can say that the Malaysian side have acted entirely in good faith."

Under the 1961 Vienna Convention, diplomats are granted full immunity from local laws while embassy staff are immune from criminal charges but not from specific civil matters.

Malaysia's Ministry of Foreign affairs said in its statement that it had "complete faith in the New Zealand legal system" and "full confidence" Ismail would be dealt with fairly.