Secretary of Defense Chuck Hagel listens to the opening statements during a House Armed Services Committee hearing on the May 31, 2014 transfer of detainees at the Rayburn Office Building June 11, 2014.

Secretary of Defense Chuck Hagel listens to the opening statements during a House Armed Services Committee hearing on the May 31, 2014 transfer of detainees at the Rayburn Office Building June 11, 2014. (Aaron Hostutler/U.S. Marine Corps)

WASHINGTON — Defense Secretary Chuck Hagel told Congress on Wednesday that the secret swap of five militants for Army Sgt. Bowe Bergdahl complied with U.S. law and was in the best interest of the United States.

In a sometimes contentious hearing before the House Armed Services Committee, Hagel said the Pentagon and the president were forced to make an “imperfect” wartime decision, and necessitated a sidestepping of the law requiring Congressional notice of Guantanamo Bay transfers.

“I recognize that the speed with which we moved has caused great frustration. We could have done a better job of keeping you informed,” Hagel said. “I can too assure you that this prisoner exchange was done legally, with substantial mitigation of risk … and in the national interest of our country.”

RELATED: More Stars and Stripes coverage of the release of Sgt. Bowe Bergdahl

Bergdahl spent almost five years of captivity in Afghanistan and was handed over by the Taliban on May 31 after the United States struck an agreement with the insurgents in talks mediated by the Persian Gulf ally Qatar to release five prisoners who had been held in Cuba since being captured during the war following 9/11.

Under a law passed last year, the president is to notify Congress of any Gitmo prisoner transfers 30 days in advance. Instead, the administration told lawmakers of the Bergdahl trade and negotiations, which began in January, only after he was in U.S. custody.

Hagel said Congress was told in 2011 and 2012 that the Department of Defense was pursuing a deal for Bergdahl in exchange for Taliban fighters, though the effort stalled.

President Barack Obama weighed the potential consequences of a leak and decided it was within his constitutional powers to order the trade without the notification, he said.

“We were told by the Qataris that a leak — any kind of leak — would end the negotiations for Bergdahl’s release,” Hagel said.

The Pentagon and the White House also knew Bergdahl would be extremely vulnerable during any movement and military forces conducting the hand-off would be exposed to ambushes in dangerous territory outside U.S. control, he said.

“The exchange needed to take place quickly, efficiently and quietly,” Hagel said. “We believed this exchange was our last, best opportunity to free him.”

Rep. Buck McKeon, R-Calif., said the Pentagon and administration may have told between 80 and 90 members of the government including employees in the DOD, State Department and Office of Homeland Security.

“We don’t know who those 80 to 90 people were,” McKeon said. “Yet in all that time, the leadership in the House … was not informed, not told of any of this.”

If lawmakers had been told, “I don’t think we would have pushed back at all,” he said.

But Republican members of the committee pressed Hagel on the threat created by releasing the five Taliban prisoners, who have been held in Cuba for 13 years.

Rep. Randy Forbes, R-Va., said the fighters were important leaders — the equivalent of the Taliban secretaries of defense, intelligence and interior — who could return to the fight and bolster the insurgency in Afghanistan.

“Does this mean you would put American lives at risk to go after them?” Forbes said. “Would we put American lives at risk if they rejoined the fight?”

Rep. Joe Wilson, R-S.C., said there has been “shock and outrage” among his constituents over the Obama administration decision to release Taliban fighters who sheltered al-Qaida following the terrorist attacks on the U.S. in 2001.

“The thought that these people wold be released were just unthinkable to the people I talked to yesterday,” Wilson said.

He said the decision is important given recent developments in Iraq where militants have captured Mosul and Tikrit, and are exerting increased influence despite a decadelong U.S. war there.

Some worried renewed violence could break out in Afghanistan, especially after the Obama administration carries out a planned drawdown beginning at the end of the year.

“My Marines at Camp Lejeune,” said Rep. Walter Jones, R-N.C., “quite frankly are tired of going to Afghanistan and getting their legs blown off.” Twitter: @Travis_Tritten

Sign Up for Daily Headlines

Sign-up to receive a daily email of today’s top military news stories from Stars and Stripes and top news outlets from around the world.

Sign up