Washington (CNN) President Donald Trump ignored Pentagon advice Friday and pardoned two service members, while also restoring the rank of a third after all faced war crimes allegations.

Trump granted full pardons to Army 1st Lt. Clint Lorance and Army Major Mathew Golsteyn, and restored the rank of Navy SEAL Eddie R. Gallagher, who had been demoted.

Defense Secretary Mark Esper and other senior military leaders had told the President that a presidential pardon could potentially damage the integrity of the military judicial system, the ability of military leaders to ensure good order and discipline, and the confidence of US allies and partners who host US troops.

A US Defense official told CNN that the leadership of the Defense Department made every effort to ensure that the President had all the necessary information at his disposal prior to making this decision. ​

Even so, the President moved ahead with the decision , acting on the second day of the House impeachment inquiry's public hearings . It was also the day that his longtime political adviser and friend Roger Stone was found guilty of lying to and obstructing Congress in a case related to Trump and the release of stolen Democratic emails in 2016 by WikiLeaks. ​​

"The President, as Commander-in-Chief, is ultimately responsible for ensuring that the law is enforced and when appropriate, that mercy is granted," the White House said in a statement. "For more than two hundred years, presidents have used their authority to offer second chances to deserving individuals, including those in uniform who have served our country. These actions are in keeping with this long history. As the President has stated, 'when our soldiers have to fight for our country, I want to give them the confidence to fight.' "

"The Department of Defense has confidence in the military justice system. The President is part of the military justice system as the Commander-in-Chief and has the authority to weigh in on matters of this nature," said Pentagon spokesman Jonathan Hoffman.

The Army said in a statement Friday that it will carry out the pardons of Lorance and Golsteyn, while noting that "The Army has full confidence in our system of justice."

The Navy tweeted Friday that it has received Trump's order to restore Gallagher's rank and is "implementing it."

Undermining authority of command

Privately wary that the President would move against their recommendations, military officials had considered in advance what public posture to take if Trump refused to listen to their advice. Rather than try to explain a decision they cannot endorse, Pentagon officials are expected to simply refer questions to the White House.

"This goes directly to our military culture," one official told CNN. Another official said, "We all view this possibility as undermining the authority of command" in military units.

The White House statement noted that "the United States military justice system helps ensure good order and discipline for our millions of uniformed military members and holds to account those who violate the Uniform Code of Military Justice. Due in part to this system, we have the most disciplined, most effective, most respected, and most feared fighting force in the world."

The statement did not acknowledge Pentagon worries that the President's actions could undermine that discipline and culture.

'Broad support'

Lorance was found guilty in 2013 of second-degree murder for ordering his men to fire on three men on a motorcycle in Afghanistan.

Trump and Vice President Mike Pence spoke with Lorance by phone Friday night and told him to "get his uniform." Lorance's legal team interpreted that to mean that he will be going free shortly, according to his lawyer John Mayer.

Gallagher was demoted after being found guilty for posing for a photo with a casualty. Gallagher had faced a court-martial for premeditated murder and attempted murder, but was acquitted. "Given his service to our Nation, a promotion back to the rank and pay grade of Chief Petty Officer is justified," the White House said.

Golsteyn has been charged with the murder of an Afghan man in 2010. He pleaded not guilty in June, according to the Army Times. His lawyer, Phillip Stackhouse, has maintained that the death occurred during a mission ordered by his superiors.

After nearly a decade, "a swift resolution to the case of Major Golsteyn is in the interests of justice," the White House said. "Clemency for Major Golsteyn has broad support," the statement continued, naming five Republican House members, an author and former Marine, and the Fox News contributor and Army veteran Pete Hegseth.

Last week CNN reported that after Army and Navy leaders were surprised by media reports that the President might intervene in the three cases, they called a meeting with Esper.

Those leaders, like most Army and Navy military and civilian officials, expressed extreme dismay about the possibility that the soldiers' sentences could be dismissed or changed, according to several sources directly familiar with their thinking.

In an effort to educate and dissuade Trump, the Defense Department put together an information package to convey to him their concerns and educate him on the issues. Esper met with Trump to urge the President to let the Uniform Code of Military Justice prevail.

He said he had "a robust discussion" with the President and offered Trump "the facts, the options, my advice, the recommendations."

Officials all pointed to a central concept that informs the US military ethos: that US forces are highly trained to operate in a legal and disciplined manner and if they are found guilty of violations, they must face punishment.

If the President "were to overuse his pardon power and in fact release soldiers who have, in every other way, have the evidence stacked against them, there certainly could be an impact on the military judicial process going forward," said John Kirby, a retired admiral who has served as both Pentagon and State Department spokesman and is a CNN military and diplomatic analyst.

"There could be an impact on military leaders and their ability to enact measures of good order and discipline. There also could be a potential crisis of confidence in the potential countries we're operating in," Kirby added.

Commander in chief

One reason US troops are as welcome as they are worldwide is because hosting nations "know the American military administers itself according to a very strict code of justice and we have a very good record of holding those troops accountable," Kirby said, even for minor scrapes such as "drunken driving overseas or getting into a fistfight in a bar."

Stackhouse, the defense counsel for Golsteyn, rejected the concerns of military leaders and veterans such as Kirby, ignoring their arguments to say essentially that Trump can do whatever he wants as commander in chief.

"To the naysayers who say dismissing the charge will undermine commanders or military justice, they still incredulously refuse to accept that President Trump is the Commander in Chief of our military and a General Court-martial Convening Authority," Stackhouse said in a statement last week.

Speaking of the career officers who lead the Army and Navy, Stackhouse said their narrative "is meant to do nothing but undermine [Trump's] leadership and pit civilian leadership against uniformed leadership."

John Maher, an attorney for Lorance, told CNN that his legal team and immediate family were all in Leavenworth, Kansas, last week waiting for his possible release. Last Friday, the inmate administration had ordered Lorance to start packing up his bags, forward his mail and close his bank account to prepare for out processing, Maher said.

Lorance "never got a fair trial," according to Maher, who said the Army lieutenant and his family have been waiting for five years for this day.

Before the decision was announced, Timothy Parlatore, an attorney for Gallagher, said his legal team had not communicated with the White House and "don't presume to know what the President is thinking," but said, "I certainly think Eddie Gallagher was treated poorly, as should every American."

Perceptions in the military differ, though, and the disconnect with the President's thinking about troops was on clear display after Trump tweeted on October 12 that "the case of Major Mathew Golsteyn is now under review at the White House. Mathew is a highly decorated Green Beret who is being tried for killing a Taliban bombmaker. We train our boys to be killing machines, then prosecute them when they kill!"

Soldiers objected quietly, but with emphatic certainty. One young officer, referring to Trump's "killing machines" comment, said, "That is not who we are."

An official explained that "the President might think they acted in patriotism, but these were war crimes." Speaking of Trump's plans to act on the three service members' sentences, this official added that "just because he can do it doesn't mean he should."

This story has been updated with additional background on the cases.