Narendra Fauji, who was set to depose in the murder case of his brother Ravindra, died on the spot, police said.
The attack was so sudden that Fauji and the police constable accompanying him had no time to react, they said.
The deceased's family members told police that there was pressure on Fauji to retract the murder case of his brother, and alleged that a BJP legislator, a Congress leader and a jailed former councillor were behind the attack.
DCP Devendra Yadav said the incident was a fallout of a personal rivalry.
The police constable, who was accompanying Fauji, is being questioned, they said.