Ugandan President Yoweri Museveni has said Somali Islamists will "pay" if they attack Uganda's capital, Kampala.
He spoke after a commander of the Somali Islamist group al-Shabab said it would target Uganda and Burundi, which have peacekeepers in Somalia.
The commander said al-Shabab wanted to retaliate after at least 20 civilians were killed as peacekeepers shelled insurgent strongholds in Mogadishu.
A spokesman for the peacekeepers said militants had caused the deaths.
The peacekeepers, who are part of the African Union force Amisom, were responding to an insurgent attack on the airport that occurred as Somalia's president was leaving for a conference in Uganda.
After heavy shelling left at least 20 dead and more than 50 injured, al-Shabab commander Sheikh Ali Mohamed Hussein said militants would attack Kampala and Bujumbura, the capital of Burundi.
"We shall make their people cry," he said. "We will move our fighting to those two cities and we shall destroy them."
Mr Museveni rebutted the threat.
"Those terrorists, I would advise them to concentrate on solving their problems," he said.
"If they try to attack Uganda, then they will pay because we know how to attack those who attack us."
A spokesman for the Amisom peacekeeping force, Maj Barigye Ba-hoku, said peacekeepers were not responsible for Thursday's civilian casualties, including those in Mogadishu's main market, Bakara.
"Al-Shabab wants to drag us into their war," he told Reuters news agency.
"They shell us and then they also shell Bakara, then they tell people there it was Amisom who killed civilians."
Somalia has been plagued by conflict since 1991.
An estimated 1.5 million Somalis are internally displaced and living in makeshift camps and hundreds of thousands have fled the country.
Islamist militants dominate much of southern and central Somalia, while the UN-backed government of moderate Islamist President Sheikh Sharif Sheikh Ahmed runs only parts of the capital.
Thursday's fighting in Mogadishu began as President Ahmed was leaving for a conference of African heads of state in Kampala.
On Friday, the conference adopted a convention on the rights of displaced people that calls on member states to provide assistance to the displaced and rebuild communities emerging from wars.