The hackers gave their account as @Anon_0x03 and said the accounts were hacked by Internet "hacktivist" group Anonymous.

They posted the stylized cartoon of Guy Fawkes associated with Anonymous and its slogan "We are legion."

The accounts were hacked late Sunday. By Monday afternoon, the ministry spokesman, Maj. Emmanuel Chirchir, had deleted the imposters' tweets from his account, declaring he had control of it again. But the hackers' tweets remained on the main Ministry of Defense account.

"The citizens of Kenya are the govt. GoK should respect the rights of all, not just a privileged few. Elitists time to quit," the hackers tweeted from the Defense Ministry account. "GoK" refers to the government of Kenya.

The hackers appeared to be familiar with Kenyan politics and political acronyms. Police blamed "tech-savvy locals" for the attack, local media reported.

"Corruption, tribalism & impunity are destroying KE. We should never have elected two criminals," another tweet from the Defense Ministry account said, referring to Kenya.

The hacker or hackers taunted police to "Catch me if you can," and urged Kenyans to reply to the tweets.

"Come on #Kenya. We don't know how long we can get away with this. Reply to this tweet now for RT with your message!" said another tweet from the Defense Ministry account. "RT" refers to a retweet.

Chirchir said the government had contacted Twitter and local technological experts about the hacking episode.

The attack comes amid insecurity, after a series of coastal attacks in recent weeks that have killed dozens. The militant group Al Shabab has claimed responsibility, but the government blames local political networks.

There appeared to be no direct link between the Shabab attacks and the anti-government tweets sent out by the hackers.

Gunmen opened fire Sunday in the coastal port of Mombasa, killing four people. In a separate attack Friday, gunmen opened fire at a bus near the resort of Lamu, killing seven.