The attack took place on the eve of a presidential vote with al Shabab spokesman Sheikh Ali Mohamud Rage saying "all those involved in the election, directly or indirectly, are apostates."
Al Shabab militants stormed a hotel in the capital of Somalia's semi-autonomous Puntland state, Bosasso, on Wednesday, killing four guards, a senior Somali official said.
"Three al Shabab fighters stormed the International Village Hotel this morning. Four guards and two of the attackers died in the fighting," Yusuf Mohamed, the governor of Bari region said.
"Fortunately, the attackers did not enter the rooms. The fighting took place inside the compound. A third fighter escaped and we are pursuing him. All the people in the hotel are safe," Mohamed added.
The hotel in the port city of Bosasso, also the capital of Bari region, is a popular tourist destination for foreigners.
Until 2011, the al Qaeda-linked al Shabab controlled most of Somalia, including the capital Mogadishu.
In the past two years, the African Union and Somali government forces have pushed al Shabab out of important urban strongholds, but the group continues its activities from bases in rural areas.
Its militants often carry out bomb and gun attacks in the capital and other regions in their attempt to overthrow the Western-backed government.
Somalia's lawmakers are due to elect a president later on Wednesday in Mogadishu.