The German national was arrested Wednesday and stands accused of “preparing a serious act of violence threatening state security”, prosecutors in the northern city of Celle said.
“During interrogation, he admitted that he planned to lure police officers or soldiers into a trap and kill them with a homemade explosive,” they said in a statement.
Investigators searching the suspect's home in Northeim, in Lower Saxony, found chemicals that could be used to make a bomb.
The accused is active in Germany's ultra-conservative Salafist scene, the prosecutors added.
Germany is on high alert for militant attacks following a string of assaults last year, the deadliest of which was a December 19th truck rampage through a Berlin Christmas market that claimed 12 lives.
The attack was claimed by terror group Isis.
German security services estimate there are around 10,000 radical Islamists in the country, 1,600 of whom are believed to have “terror” links.