Members of the extremist group al-Shabab killed six people in an attack on a residential compound in the northeastern Kenyan town of Mandera which borders Somalia.
About 27 people were rescued by the security forces who acted quickly to thwart the assailants.
"If not for the quick response by our security forces, we would be talking of many more casualties now," Mandera County governor Ali Roba told Reuters.
The fundamentalist group said they were targeting Christians when they attacked the building complex which housed non-ethnic Somalis and non-Muslims.
The Associated Press quoted an anonymous al-Shabab militant saying on Andulus radio station: "It was a well-planned attack which targeted Christian members in Mandera."
The terrorists attacked the building around 2 AM when people were sleeping. They used a grenade to gain entry into the complex, before firing indiscriminately at the building.
The BBC reported that the group wanted Christians to abandon the region which it claims as a Muslim area.
Government spokesperson Erick Kiraithe said that it is not yet confirmed how many terrorists were involved in the attack, as they had escaped across the border.
"We had intelligence that al-Shabab terrorists were targeting government agencies and civilians, but it was not enough to go by," Kiraithe told Daily Nation.
"An attack on one Kenyan is an attack on all Kenyans; those agents of Lucifer will not succeed here. The government takes this opportunity to send our deepest condolences to the families of those who lost their lives in this heinous attack," he added.
Security personnel Mohamud Ali Saleh said that the militants were taking revenge of the defeat they suffered in Somalia.
"These criminal gangs are desperate to hurt innocent Kenyans since they were defeated badly and routed out of all their hideouts in the neighbouring country," he said.
Al-Shabab has carried out attacks on the Somali border on many occasions to compel Kenyan government to withdraw its troops from African Union force in Somalia.
The militant organization rebelled to dislodge the internationally-recognized government in Somalia in 2007.
By August 2011, the African Union Mission had taken control of the capital city Mogadishu, and a federal government of Somalia was established by August 2012.
In the aftermath of the losses, al-Shabab directed its focus on Kenya and increased insurgency to coastal areas which are popular with the tourists. The group also claimed responsibility for an attack on the Westgate shopping mall in capital city Nairobi in 2013, and on Garissa University College in April 2015.