The man, who lived in Gelsenkirchen, struck a patrol car with an object on Sunday and sought to assail officers standing by the vehicle “with a raised object,” a police spokesman told AFP.
Officers noted that the attacker was holding a knife behind his back, he added.
Despite several warnings from officers, the man refused to stop his assault, leading a 23-year-old policeman to fire a shot that killed him.
Asked to confirm reports that the man cried out “Allah Akbar” (“God is greater”) during the assault, the police spokesman would only say they are “rumours”.
Germany remains on alert following a series of Islamist attacks, the deadliest of which was a truck rampage at a Berlin Christmas market in 2016 that killed 12 people.
Dozens of suspects have been arrested or charged over alleged terror plots in recent years.