Security sources say the central prison, which is holding members of the Al Qaeda-affiliated Al Shabab terrorist group, in the state of Puntland came under attack in the early hours of Friday.
At least seven soldiers have been killed when fighters of the Somalian armed group Al Shabab stormed a jail in the semi-autonomous state of Puntland, police and the group said.
Al Shabab said it had freed at least 400 prisoners, many of them its members, in its assault on the main prison in Bosaso, Puntland's largest city, in the early hours of Friday.
The authorities did not confirm that figure.
"Last night many well-armed men attacked us from various directions. We fought back but finally they entered the central jail by force using explosions. They freed the prisoners and took most with them," Mohamed Abdi, a prison guard, told Reuters.
"There was a hellish battle ... As I fought inside, we lost five soldiers."
He said two other soldiers who had been sent to reinforce the regular prison guards were killed in their car which was set on fire.
READ MORE: Deadly twin explosions strike Somali capital
Al Shabab confirmed that its fighters had carried out the attack and said they had freed at least 400 prisoners. The group often exaggerates its successes in such assaults.
"The prisoners included men and women who were Al Shabab members and were in jail for over 10 years," Abdiasis Abu Musab, Al Shabab's military operations spokesperson, told Reuters.
Al Shabab frequently carries out such attacks in Somalia and elsewhere as part of its campaign to oust the central government in Mogadishu and establish its own rule based on its strict interpretation of sharia law.
Bosaso police commander, Col Hussein Ali, said an operation was underway to recapture prisoners who had escaped or had been taken away by the fighters.
Bosaso is a commercial port city located 1,388 km (862 miles) from the capital Mogadishu.
The Somali-based terrorist group is also active in Bari.
Paramilitary forces of Somalia's semi-autonomous Puntland region have fought against the terror group many times in the Galgala mountains in the province.