The two officers stopped a car for a traffic violation and escorted the vehicle to a police station in the Pangani district of Nairobi where it exploded, killing the two occupants and the police officers.
"I mourn the loss of the the two gallant officers who've died in their line of duty as they were defending and protecting our beloved country," David Kimayo, the Inspector General of Kenya's national police, wrote on his Twitter account.
He stressed that the vehicle could have caused "huge damage" had it exploded somewhere else.
Kimayo suggested that terrorists were responsible and said "I fully declare war" on terrorism.
In recent years Kenya has been the target of terrorist attacks conducted by the Somalian terrorist group al-Shabab in retaliation for Kenya's involvement in Somalia. Last September, al-Shabab claimed responsibility for an attack on a Nairobi shopping mall that resulted in 67 deaths, with dozens wounded.