A Kenyan police officer went on a shooting spree on Thursday, killing seven of his colleagues, including a hostage response team member, before the standoff ended in a shootout, a police statement said.

The siege in Kapenguria began early on Thursday when the attacker, identified as Abdilhakim Maslah, opened fire on his fellow officers, leading to a hostage situation.

Police at first suspected the attacker had ties to the al-Shabab group based in neighbouring Somalia.

The police report says Maslah, a station guard, got off work Wednesday night but returned to the Kapenguria station shortly after 5am on Thursday and started shooting.

A separate police statement to the media said the officer, "for yet unknown reasons, went berserk and grabbed a firearm" and started shooting.

That statement said the officer wore a "turban that covered his whole face, leading to the previous suspicions" that he was an extremist.

Earlier, Police Inspector General Joseph Boinnet had said in a statement that commandos had surrounded the police station in an attempt to bring the standoff to an end. 

"His [the attacker's] attempts to escape were thwarted by quick arrival by other officers," Boinnet said.

Kenya's Nation news organisation reported that five police officers, including a senior officer, were among the dead, quoting West Pokot County Commissioner Wilson Wanyanga.

Kenyan television channel KTN said as many as six officers had died in Kapenguria.

Police commandos were deployed to rescue prisoners held at the station and end the standoff, Kenya's police chief, Joseph Boinnet, said before the crisis ended.

Boinnet, the police chief, said the gunman's escape was "thwarted by quick arrival by other officers".

All but one of the officers killed worked at the station. The station commander was among them, West Pokot County Commissioner Wilson Wanyanga said.

Source: Al Jazeera and agencies