A bomb blast and a shoot-out between Islamists and troops from the semi-autonomous Puntland region have left 31 people dead or wounded, officials say.
Fighters from the al-Qaeda-linked al-Shabab group attacked a military base and planted a roadside bomb, the officials said.
Al-Shabab fighters have reportedly moved to Puntland in recent months.
Their move comes as African Union-backed government forces gain ground in their stronghold of southern Somalia.
In October, al-Shabab, which is affiliated to al-Qaeda, lost control of the key port city of Kismayo to AU troops, the Somali army and a pro-government militia.
Puntland Information Minister Mohamed Aydid told the BBC Somali Service that a truck carrying soldiers was targeted by a roadside bomb near Bossaso, the main commercial hub in the semi-autonomous region.
Ten soldiers were either killed or wounded in the attack, he said.
Heavily-armed al-Shabab fighters also launched an assault on a military base in the area, but were repelled by troops, Mr Aydid added.
“They fled to their hide-outs in the Galagalo mountains,” he said.
In a statement, the Puntland government said two of its soldiers were killed in this attack.
Its intelligence suggested that at least seven al-Shabab fighters were killed and more than 12 wounded as Puntland government troops fought back, the statement said.
“Puntland forces are pursuing al-Shabab tracks into the mountains,” the statement added.
Al-Shabab confirmed the attacks, saying it had killed 29 troops.
Puntland officials said they had also seized a number of weapons consignments destined for al-Shabab.
The weapons had been sent across the sea from Yemen, the officials said.
BBC Somalia analyst Mary Harper reports that dozens of al-Shabab fighters have in recent months moved north to the Galagalo mountain range, as the Somali army and 18,000-strong AU force capture territory in southern Somalia.
There have however been some major al-Shabab ambushes in southern Somalia in the past few days.
On Tuesday, the group attacked an army base near the town of Jowhar, one of its last urban strongholds, and on Monday it ambushed a convoy in which three government ministers were travelling near the port of Merca.
These incidents prove that although al-Shabab has lost key areas in the past year, including Kismayo and several districts of the capital Mogadishu, it is by no means a spent force, our correspondent says.