President Rodrigo R. Duterte has pardoned a US marine whom a Philippine court convicted in 2015 for killing a transgender Filipino sex worker in a case that had ignited anti-American sentiment in the former US colony.

Joseph Scott Pemberton, whose release for good conduct was held by prison officials after an appeal by his victim’s family, had been given the absolute pardon, Foreign Affairs Secretary Teodoro M. Locsin, Jr. tweeted on Monday.

“Cutting matters short over what constitutes time served, and since where he was detained was not in the prisoner’s control — and to do justice — the President has granted an absolute pardon to Pemberton,” he said from the presidential palace.

An Olongapo trial court convicted Mr. Pemberton for homicide in 2015, sentencing him to six to 10 years in jail.

Mr. Pemberton could have faced a life sentence had the judge granted prosecutors’ request for a murder conviction. The court cited mitigating circumstances, saying Mr. Pemberton was drunk and got confused after discovering that the person he had hired for sex was male.

Jeffrey Laude, a 26-year-old male sex worker who identified as a woman, was found strangled in October 2014 in a motel.

“That means Pemberton can go free now,” presidential spokesman Harry L. Roque told GMA News in Filipino, according to a recording of the interview shared by the media network on Viber.

“The President did not erase Pemberton’s conviction,” he said. “He is still a killer but the President has erased his punishment.”

Mr. Duterte said he pardoned the American soldier because he had been treated unfairly.

In a televised speech on Monday night, the President said he had consulted Justice Secretary Menardo I. Guevarra and Executive Secretary Salvador C. Medialdea about the pardon.

The court last week ordered Mr. Pemberton’s release for good conduct. The Justice department earlier said the American soldier would remain detained pending the appeal of the victim’s family.

Mr. Guevarra had said the agency would separately appeal Mr. Pemberton’s release this week. — Gillian M. Cortez