WASHINGTON — The White House Wednesday defended the treatment of an alleged leader of Somalia's Shebab Islamist insurgency who was interrogated for two months on a US warship, saying his detention was lawful.

In the first known case of the secret detention of a terror suspect by the administration of President Barack Obama, Ahmed Abdulkadir Warsame was captured in the Gulf on April 19 and kept aboard a US Navy ship at sea.

The Somali national was indicted on Tuesday in a New York court on charges of providing material support to both the Shebab and Al-Qaeda in the Arabian Peninsula, the Yemen-based branch of the Islamist terror group.

Warsame, 25, "was detained lawfully, under the law of war, aboard a US Navy ship until he was transferred in the US for prosecution," White House spokesman Jay Carney said.

"The International Committee of the Red Cross was told of Warsame's detention on the ship, visited the site of detention and had the opportunity to interview the detainee aboard the ship," he added.

The Justice Department said in a statement that Warsame was informed of his rights, but had agreed to keep talking to law enforcement officials for seven days after that. He was turned over to the FBI before being flown to New York.

Warsame was questioned first by the military and then by other government interrogators, Pentagon spokesman Colonel Dave Lapan told reporters.

He said the interrogations on the ship were carried out strictly according to the Army's guidelines for questioning detainees, which prohibit the use of torture or abusive techniques.

"The Army Field Manual was adhered to during this interrogation," Lapan said.

The military carried out the operation that resulted in Warsame's capture, Lapan indicated, but would not say whether special operations forces were involved or what naval ships participated.

"It was a targeted counter-terrorism operation. We didn't just happen upon him," Lapan said.

"We developed intelligence and we conducted the mission."

Carney said the government's goal is to detain terror suspects when possible "to preserve the opportunity to elicit valuable intelligence that can help us protect the American people."

He added: "In this case the government has been able to acquire very valuable intelligence."

Warsame faces nine counts including acting as a go-between between the two groups, providing them with both money and training between 2007 and 2011. He faces a life sentence if convicted on the terror and weapons charges.

The case provides an insight into how the Obama administration plans to question and try detainees outside war zones after closing the CIA's secret prison network.

Last month, Obama's nominee to be the next chief of US Special Operations Command, Vice Admiral William McRaven, told lawmakers that the United States could hold terror suspects on naval ships if necessary -- until legal charges were filed in court.