High-profile attacks by the armed group al Shabaab at the Westgate Shopping Mall in 2013 and Garissa University in 2015 killed more than 200 people. The events changed the way government deploys ground forces and carries out counter-terrorism activities.
The army took over control of the porous border with Somalia from the police. Since then, soldiers have spearheaded a large-scale operation in the Boni national reserve, pushing al Shabaab fighters back into Somalia, reducing the group's capacity to recruit and operate inside Kenya.
For years, Boni Forest in the national park was easy cover. Analysts say Kenya’s success has made it a blueprint for dealing with violent groups in the region.
"When you look at the wider international picture, you'll find that starting from the 9/11 attacks in the US, Kenya thought they were clear of this international terrorism, until the threat came to Somalia and even closer, into the border," said Ahamed Mohammed, a retired brigadier-general with the Kenyan army.
"Being one of the major victims … we had to join the global war on terror," he said.
Kenyan success is based on close cooperation with the USA and the UK. Mohammed said advanced surveillance technology has given Kenya the ability to monitor the movements and communications, even identifying lone-wolf attackers.
"In the last few years there has been very good cooperation," Mohammed said. "International powers bring in the element of technology, which actually even picks out individuals whom you're after … our key benefit has been in the area of intelligence and getting first-hand information."
Once safe havens for al Shabaab, Kenyan security forces have taken back territory across Garissa and Lamu counties.
"We're happy people have been able to move back to their normal ways of life — going to the market, going to their farms and doing [business]," said Joseph Kanyiri, the commissioner of Lamu county.
On Monday, a court ruled three men must stand trial on charges they were involved in a deadly attack on a Nairobi shopping mall in 2013.
A fourth suspect was freed because of a lack of evidence. Al Shabaab claimed responsibility for the brazen attack.
Kenyan leaders have little doubt that security has improved in recent years. But many Kenyans still living in camps near the front line say pushing al Shabaab into Somalia has given way to unforeseen threats closer to home.
As people fled the conflict zone, armed Kenyan herders took over abandoned farmland to graze their animals and are now threatening anyone who tries to return. While the police and army remain focused on mitigating the external al Shabaab threat, those displaced by fighting are still too afraid to go home.
"When I went back to my farm and the rest of the people came back we were attacked by the herdsmen, [they] beat us," said John Mtemi Mwendwa, a displaced farmer in Katsaka Kairo IDP camp.
Ground forces carry out military operations while local leaders conduct community outreach and engagement programmes to undercut al Shabaab propaganda in their communities.
Alongside soldiers, Kenyan President Uhuru Kenyatta even thanked civilians in his New Year's address to the nation for their role in disrupting armed groups.
"Our security services have continued working hard and intelligently," Kenyatta said.
"A big part of their success is coming from citizens stepping up to share information they have, while others take steps to completely delegitimise and de-glorify terrorism among its vulnerable targets for recruitment. As your president, I thank every man and woman who has played a role in our national campaign against violent extremism."