At least 48 people have died after al-Qaeda-linked militants attacked hotels and a police station in a Kenyan coastal town, officials say.
Witnesses in Mpeketoni said gun battles lasted several hours, while several buildings were set on fire.
The town is on the mainland near Lamu island, a well-known tourist resort.
Somalia's al-Shabab group said the attack was carried out to avenge the presence of Kenyan troops in Somalia and the killing of Muslims.
Kenya sent troops to Somalia in 2011 to help the weak UN-backed government defeat the militants.
The BBC's Anne Soy in Mpeketoni says she was told the gunmen shot dead anyone who was unable to recite verses from the Koran.
This is the most deadly attack in Kenya since last September, when at least 67 people were killed during a siege by al-Shabab fighters at Nairobi's Westgate shopping centre.
Interior Minister Joseph Ole Lenku described the attackers as bandits, and said they had crossed a "red line".
Police fought fierce battles with the gunmen, who fled into a nearby forest, Mr Ole Lenku said.
The attack started at 20:30 local time (17:30 GMT) on Sunday as locals were watching a football World Cup match on television.
Local residents told the BBC the gunmen hijacked a van and used it to attack various locations across Mpeketoni, which tourists travelling by road pass through before crossing to Lamu.
Our correspondent says there are five burnt-out police vehicles in front of the police station, which was the first building to be attacked.
She says she can still smell burning rubber, while smoke is billowing out from one of the vehicles.
Timeline of Somali raids in Kenya- September 2011: UK national Judith Tebbutt kidnapped and her husband David killed in raid on Kiwayu island, north of Lamu. She was released six months later by a pirate gang
- October 2011: Kenya sends troops into Somalia following Tebbutt's kidnapping and cross-border raids by al-Shabab; Al-Shabab warns of revenge attacks
- Since then, numerous attacks in Nairobi, Mombasa and north-eastern region of Kenya, inhabited by ethnic Somalis
- September 2013: At least 67 people killed after al-Shabab militants take control of Westgate shopping centre in Nairobi
- May 2014: UK issues travel advisory, warning of increased risk of terror attack in Nairobi and coastal areas - UK tourists evacuated
- June 2014: At least 48 people killed in raid on Mpeketoni
All those killed are believed to be locals. The Kenya Tourism Board (KTB) says no foreigners were in the town at the time of the attack.
Witnesses said gunmen, who had their faces covered, threw explosives into the local police station before entering and stealing weapons.
Kenya has been on high alert recently following warnings that al-Shabab was planning more attacks.
The US and UK have issued advisories to their nationals to keep away from parts of the Kenyan coast.
Sunday's attack comes days after the UK government closed its consulate in the port city of Mombasa, citing heightened security threats.
Surveillance aircraft
District deputy commissioner Benson Maisori said hotels, restaurants, banks and government offices had also been torched, the AFP news agency reports.
"There were around 50 attackers, heavily armed in three vehicles, and they were flying the Shabab flag. They were shouting in Somali and shouting 'Allahu Akbar' [God is Great]," he said.
Lamu County police commander Leonard Omollo told Reuters news agency that the gunmen singled out men, sparing the lives of women and children.
"They came to our house at around 8pm and asked us in Swahili whether we were Muslims," local resident Anne Gathigi told the AP news agency.
"My husband told them we were Christians and they shot him in the head and chest," she said.
Kenyan army spokesman Major Emmanuel Chirchir said surveillance aircraft had been dispatched to the region to help track down the attackers.
Nearby Lamu island is a popular tourist destination with ancient architecture that is listed as a Unesco World Heritage site.
UK national Judith Tebbutt was kidnapped by gunmen in September 2011 from the remote resort of Kiwayu, north-east of Lamu.
The gang also shot dead her 58-year-old husband, David Tebbutt.
Mrs Tebbutt was released six months later after a ransom was paid to pirates holding her captive in Somalia.
Are you in Mpeketoni? Have you been affected by the recent activities? You can email haveyoursay@bbc.co.uk using the title 'Mpeketoni'.
Or get in touch using the form below.
Send your pictures and videos to yourpics@bbc.co.uk or text them to 61124(UK) or +44 7624 800 100 (International). If you have a large file you canupload here.