US forces have captured a top al-Qaeda figure in a raid in Libya, while another raid on a Somali town failed to capture or kill the intended target belonging to the al-Shabab armed group.

The raids on Saturday came two weeks after an attack on a Nairobi mall in Kenya left at least 67 people dead. The al-Qaeda-linked al-Shabab had claimed responsibility for the attack.

The Pentagon said senior al-Qaeda figure Anas al-Liby was seized in the raid in Libya. Liby, believed to be 49, has been under US indictment for his alleged role in the East Africa embassy bombings that killed 224 people.

The US government had been offering a $5m reward for information leading to his capture, under the State Department's Rewards for Justice programme.

"As the result of a US counter-terrorism operation, Abu Anas al-Liby is currently lawfully detained by the US military in a secure location outside of Libya," Pentagon spokesman George Little said without elaborating.

Hours later, the Libyan government sought an explanation from the US over the unauthorised military operation.

Al Jazeera's Rosiland Jordan, reporting from Washington, said the US had hunted Liby for a long time.

"He has been on the run, at least until Saturday when forces apparently swooped down on him when he was returning home from morning prayers and took him away."

CNN reported in September last year that Liby had been seen in the Libyan capital, Tripoli. It quoted Western intelligence sources as saying there was concern that he may have been tasked with establishing an al-Qaeda network in Libya.

Somalia raid

The Pentagon confirmed that US forces had also been involved in an operation against what it called "a known al-Shabab terrorist" in Somalia’s Barawe town, but gave no more details.

Al Jazeera's Peter Greste, reporting from the capital Mogadishu, said US sources confirmed they had failed to capture of kill their intended target.

"That seems to have been confirmed by al-Shabab who says that only one of its guards was killed in the operation and that there were no senior military commanders at their headquarters at the time of the attack," Greste said.

Our correspondent said he understood the target of the operation was Ahmed Godane, the leader of al-Shabab.

US sources told the Reuters news agency that their forces, trying to avoid civilian casualties, disengaged after killing some al-Shabab fighters. They said no US personnel were wounded or killed in the operation, which one US source said was carried out by a Navy SEAL team.

Firefight

Residents said fighting erupted at about 3 a.m. "We were awoken by heavy gunfire last night, we thought an al-Shabab base at the beach was captured," Sumira Nur, a mother of four, told Reuters from Barawe.

"We also heard sounds of shells, but we do not know where they landed.".

US Secretary of State John Kerry, commenting on the strikes, warned al-Qaeda they "can run but they can't hide."

In 2009, helicopter-borne US special forces killed senior al-Qaeda fighter Saleh Ali Saleh Nabhan in a raid in southern Somalia. Nabhan was suspected of building the bomb that killed 15 people at an Israeli-owned hotel on the Kenyan coast in 2002.

The US has used drones to kill fighters in Somalia in the past. In January 2012, members of the elite US Navy SEALs rescued two aid workers after killing their nine kidnappers.