BERLIN  President Horst Köhler of Germany resigned Monday amid a barrage of criticism for remarks he made during a visit to Afghanistan.

It was the first time in four decades that a German president has quit the post, the nation’s highest even though it is largely ceremonial.

Mr. Köhler set off the criticism when he said in an interview with Deutschland Radio, the public broadcasting station, that German soldiers serving in Afghanistan or with other peacekeeping missions were deployed to protect German economic interests.

His resignation was another blow for Chancellor Angela Merkel, a close friend and an important conservative ally. She had lobbied hard for him to become president, first in 2004 and again in May 2009, and his departure came just a week after another leading conservative politician, Roland Koch, resigned as premier of the state of Hesse, saying he had had enough of politics.