NAIROBI, Kenya — Masked gunmen hurled grenades into two churches in eastern Kenya on Sunday and then sprayed gunfire at fleeing worshipers, killing at least 15 people in one of the worst terrorist attacks Kenya has suffered in years.

When Kenyan forces stormed into Somalia eight months ago, Somalia’s fiercest militant Islamist group, the Shabab, vowed to wreak vengeance, saying it would topple Nairobi’s skyscrapers and kill Kenyan civilians.

The skyscrapers are still standing, but militants believed to be connected to the Shabab have carried out more than a dozen attacks in Kenya, scaring off tourists and putting a serious dent in this country’s economy and sense of security.

At 10:30 a.m. Sunday, four gunmen attacked the African Inland Church in Garissa, an outpost town in the arid flatlands near the border with Somalia. Kenyan police officials said the gunmen had hurled two grenades into the church and shot and killed two police officers who had been posted at the church’s door because of several recent attacks in Garissa.