The officer first shot and killed his wife at their home before setting off with his service-issued AK-47 rifle to shoot dead another four people, the directorate said on its Twitter account, describing the shooter as a “rogue officer”.
Three of the men who were killed were mourners who had just attended preparations for a funeral, the DCI said.
“After killing the three, the cop then turned his rifle at two boda boda (motorcycle) riders, one of whom lost his life while undergoing treatment,” police said.
Francis Wahome, the officer in charge of Nairobi’s Dagoretti area, had earlier confirmed the incident and put the number of people the officer killed at six. A police report had also put the number of dead at six.
Angry residents near where the incident took place later set fire to tires on a road in a protest against the violence, a Reuters witness said.
In a 2010 incident, a police officer in Siakago town, 120 km (74 miles) northeast of Nairobi, shot 10 people dead including two of his colleagues.
A police spokesman said at the time the officer tried to shoot himself but had run out of ammunition, forcing him to surrender to police.
This story has been updated with new information.