Somali insurgents on Monday mounted an ambitious attack on a base where US special forces train Somali commandos, while an Italian military convoy was hit in a separate blast in the capital Mogadishu.
No casualties were reported in either attack, US and Italian officials said.
Twin vehicle-borne bombs at the Baledogle base, where Somali forces and Ugandan peacekeepers are also housed, were followed by small arms fire, a security source and Somali police said.
"Two suicide car bombs ... tried to attack Baledogle airport but they detonated outside the airport gate," police Major Abdullahi Nur told Reuters.
The al Qaeda-linked group al Shabaab said it carried out the attack.
Baledogle is about 100 km (60 miles) west of Mogadishu. Insurgents attacked the base in February using mortars, but caused no casualties.
"The security forces stopped this ultimately failed attack due to their alertness and swift response, not allowing the attackers to breach the outer defensive perimeters of the base," the US embassy said in a statement.
The US military said that US and partner forces had killed 10 militants and destroyed a vehicle after the attack.
Somali state news agency SONNA reported that all the militants who took part in the assault had been killed.
"In response to this attack and in self-defense, US Africa Command conducted two airstrikes and used small arms fire targeting al Shabaab terrorists," a US military statement said.
The military added that no US or partner forces were injured in the al Shabaab attack.
The attack showed al Shabaab maintains a good intelligence network and can mount complex operations, said Hussein Sheikh-Ali, a former national security adviser and founder of the Mogadishu-based security think-tank the Hiraal Institute.
The attack hit a part of the base that houses US special forces, who supervise Somali forces on operations, he said.
"It implies they have a high intelligence and a degree of capability just to get close to that place," he told Reuters.
The base is also used to mount drone attacks.
Monday's attacks follow a dip in US airstrikes in Somalia. Africa Command has carried out four in the past two months, compared with 28 in the first three months of 2019.
The United States has carried out about 43 strikes against al Shabaab so far this year, against a total of 47 in 2018.
Last year the Pentagon said it would withdraw hundreds of troops focused on counterterrorism operations in Africa, as the military increasingly focuses on China and Russia.
The Pentagon has already cut about 300 troops from the continent but the head of US forces in Africa is undertaking a broad review on whether another 300 troops still need to be cut.
Al Shabaab said its fighters had breached the base perimeter, though police denied that.
"In the early hours of Monday morning, an elite unit of soldiers from Harakat Al-Shabaab Al Mujahideen's Martyrdom Brigade launched a daring raid on the US military base," the group said in a statement.
"After breaching the perimeters of the heavily fortified base, the mujahideen (holy warriors) stormed the military complex, engaging the crusaders in an intense firefight."
Al Shabaab is fighting to overthrow the weak, U.N.-backed Somali government and enforce its own strict version of Islamic law in a country riven by civil war since 1991.
In a separate attack on Monday in Mogadishu, a roadside bomb targeted an Italian military convoy. A Reuters journalist saw a seriously damaged armoured vehicle bearing a small Italian flag sticker. The Italians are part of a European Union mission training Somali forces.
The incidents follow several other major al Shabaab attacks.
On Sept. 22, insurgents attacked a base in El Salini, southwest of Mogadishu, using a suicide car bomb and gunmen.
A week earlier, al Shabaab said it killed 14 Burundian peacekeepers. The African Union said three Burundians were killed. Burundi did not respond to requests for comment.