The 26-year-old Turkish-German was convicted of grievous bodily harm, breaching the peace, and resisting a law enforcement officer.
A member of the fundamentalist Salafist branch of Islam, the man, named only as Murat K., by German media, he confessed to stabbing two police officers, which he justified with his religious beliefs.
Murat K. said during his trial, "one cannot expect from a Muslim that he remain calm when the prophet is being insulted." He declared the Bonn district court as illegitimate and said he only answered to Allah.
The man stabbed the officers in the thigh when a demonstration turned violent after members of the right-wing group Pro-NRW publicly displayed cartoon depictions of the Prophet Muhammad.
One of the cartoons showed Muhammad with a bomb in his turban, Focus magazine reported.
Twenty-nine police officers were injured and more than 100 people were arrested during the demonstration in front of the King Fahd Academy in Bonn, held in the run-up to the state elections in North Rhine-Westphalia.
The man's attack on the police officers was caught on video tape, and both officers later required operations for their injuries.