In a reversal that is being celebrated by lawmakers and legal activists, the U.S. Army has decided to allow a decorated Green Beret who confronted an Afghan child rapist to continue his service.

The Army moved to retain Sgt. 1st Class Charles Martland after initially planning to kick him out of the service for physically confronting an Afghan Local police commander in 2011 for allegedly raping a young boy repeatedly. The decision, first reported by Fox News and confirmed to the Washington Free Beacon by a spokesman for the Army, was made after lawmakers and legal activists led charges to advocate for Martland’s reinstatement.

Rep. Duncan Hunter (R., Calif.) has fiercely advocated on Martland’s behalf for months, calling the soldier a "war hero" for defending a child victim of sex abuse. Hunter and Rep. Vern Buchanan (R., Fla.) introduced a House resolution last September demanding that Martland be reinstated.

"I am real thankful for being able to continue to serve," Martland told Fox News. "I appreciate everything Congressman Duncan Hunter and his chief of staff, Joe Kasper did for me."

Kasper told the Free Beacon Friday that Hunter was notified by Patrick Murphy, the acting secretary of the Army, of the decision Thursday night.

"Representative Hunter got the call last night from the acting Army secretary and he was elated. He thanked him for doing the right thing, and for putting Charles back in the fight—which is what Charles always wanted," Kasper said.

"We’ve worked a lot of these types of cases as an office and this is perhaps the most gratifying outcome of them all. The Army deserves credit here too. The new leadership team is different than the old, and this decision is proof of that fact."

While serving in Afghanistan in 2011, Martland and another soldier physically confronted an Afghan Local police commander at an outpost for allegedly kidnapping and repeatedly raping a young boy over multiple days. They acted after the boy’s mother, who was also attacked by the Afghan commander, sought help. Martland and his team leader reportedly shoved the Afghan commander to the ground. They were eventually removed from the base.

Martland was ordered to be discharged by November of last year after facing a Qualitative Management Program (QMP) review board. Martland appealed the decision and was denied outright, though he was allowed to resubmit an appeal. The Army Board for Correction of Military Records eventually made a determination that removed Martland from the QMP list, Army spokesman Lt. Col. Jerry Pionk said in an emailed statement, which will allow him to remain in the service.

"The Army Board for Correction of Military Records considers each case on its own merit when determining to grant or deny an applicant’s request," Pionk said. "It is incumbent upon the applicant to provide evidence, argument, and relevant documents in support of demonstrating an alleged error or injustice. In addition to information provided by the applicant, boards also consider information in available personnel, medical and staff agency records, and information provided by subject matter experts."

Buchanan reacted positively to the decision but wondered why it "took so long" for the military to reverse the decision.

"While the Pentagon’s refusal to correct this injustice quickly was troubling, I’m glad that he will be able to continue serving our country in uniform," Buchanan said in a statement Friday. "Sgt. Martland’s actions to stop an Afghan rapist from abusing children in 2011 warranted appreciation, not punishment. We need to make sure this never happens again."

Martland was one of multiple soldiers and Marines highlighted in a New York Times article last September who had allegedly been discouraged from reporting suspicions of Afghan forces sexually abusing children in Afghanistan. Pentagon leaders have insisted that no such policy exists.

Martland’s case has garnered national attention. The American Center for Law and Justice, a constitutional law firm based in Washington, D.C., launched a petition six months ago calling for his reinstatement, and it accumulated nearly 350,000 online signatures. The group also started a letter-writing campaign that resulted in more than 65,000 Americans sending letters to Defense Secretary Ash Carter and acting Army Secretary Murphy urging the service to reinstate Martland.

"Justice has been served. The U.S. military has a moral obligation to stop child sexual abuse and exonerate SFC Martland for defending a child from rape," Jay Sekulow, the chief counsel at the law center, said in a statement. "The Army finally took the corrective action needed and this is not only a victory for SFC Martland, but for the American people as well."