BERLIN (Reuters) - Former foreign minister Frank-Walter Steinmeier was elected Germany’s president on Sunday, the 12th person to hold the largely ceremonial post in the post-war era.

Steinmeier, a Social Democrat who had served as foreign minister until last month, won 931 of the 1,239 valid votes by lawmakers and representatives of Germany’s 16 federal states. There 103 abstentions and 14 votes were invalid.

After Bundestag president Norbert Lammert announced the results, all representatives held a standing ovation except for a few dozen members of the populist Alternative for Germany (AfD) party.

The anti-immigrant AfD, which has no lawmakers in the lower house but holds seats in 10 of Germany’s 16 state parliaments, is forecast to be the third-largest party after a general election on Sept. 24.

The AfD filed its own candidate, who received 42 votes.

“I have faith in him to lead our country in these difficult times,” Chancellor Angela Merkel, who is seeking a fourth term, said after the vote.

The Kremlin said in a statement that Russian President Vladimir Putin had congratulated Steinmeier in a telegram and invited him to visit Moscow.

Slideshow ( 9 images )

Steinmeier last year drew criticism when he said NATO’s decision to stage military maneuvers in eastern Europe amounted to “saber-rattling”. His Social Democrats prefer a softer stance towards Russia than Merkel’s conservatives.

Russia wants the European Union to lift sanctions imposed over its annexation of Crimea and backing of separatist rebels in eastern Ukraine.

The German constitution mandates that a special assembly is convened to elect presidents. It includes 630 lawmakers in the Bundestag lower house and an equal number of representatives from the federal states.

Current President Joachim Gauck steps down on March 18.