Werner S. was found guilty of grievous bodily harm and for threatening the mayor, but the court did not find sufficient evidence to convict him of attempted murder.
The defendant had told the court that he did not plan to hurt the mayor, Andreas Hollstein, but simply scare him.
The assault in November shocked Germany, and reports initially said that the attacker was driven by anger against politicians for allowing more than a million asylum seekers into Germany since 2015.
Hollstein said that the assailant had asked him if he was the mayor before pulling the knife. The attacker also told him: "You let me die of thirst and take in 200 refugees in Altena."
But the assailant denied during the trial that he was motivated by xenophobia.
Altena, a town of about 17,000 people was well known for taking in a larger share of asylum seekers than legally required.
Hollstein, who accepted a national award from Merkel in May 2017 for the town's work with refugees, had said that Altena had welcomed about 450 people and that he had no plans to reverse his stance.
Germany remains deeply divided over the country's humanitarian responsibilities and its ability to integrate newcomers.
While most mainstream parties back the principle of Germany taking in people fleeing war zones such as Syria, the backlash led to the far-right Alternative for Germany (AfD) party winning its first seats in parliament in September's general election.