Somali Islamist terrorist group al Shabaab, which attacked the Westgate shopping mall in Nairobi last September, said it had staged an attack in the coastal area.
Nine people lost their lives at the Hindi trading centre in Lamu county, near the scene of attacks in which 65 people were killed last month.
Another 20 people were killed in another attack in the Gamba area of neighbouring Tana River county.
Both counties are situated north of Mombasa.
Officials said a group of 10-15 men struck at Hindi, nine miles from the town of Lamu, and close to the town of Mpeketoni, which was targeted in one of the attacks in June.
Abdallah Shahasi, the area's chief, said: "They went around shooting at people and villages indiscriminately."
Al Shabaab said it had broken into the police station at Gamba and freed suspects from the detention cells.
A police source said: "They killed some of our colleagues and freed Muslim detainees. Some of those freed were linked to the Mpeketoni attacks two weeks ago. We still don't know how many detainees were freed until we verify with registers at the station."
Lamu county commissioner Miiri Njenga said the attackers targeted government offices and some properties were burnt down.
The wave of gun and grenade attacks along the coast and in Nairobi has hurt the tourism business, a leading source of foreign exchange.
The Kenyan Red Cross said three people were taken to hospital with injuries.