BERLIN — A rights activist and former Lutheran pastor was overwhelmingly elected as Germany’s 11th postwar president on Sunday, putting former East Germans in the nation’s two highest offices at a time when it is being called on to assume a greater leadership role in Europe.

The new president, Joachim Gauck, won 991 out of 1,228 votes cast by a special committee of lawmakers and representatives that chooses the head of state. His closest rival, Beate Klarsfeld, a prominent anti-Nazi campaigner, won 126 votes.

“What a beautiful Sunday,” Mr. Gauck, 72, said at the start of his brief acceptance speech, recalling the excitement of his first election 22 years ago when East Germans were finally able to select their own leaders, before unification with the West and after decades of a Communist dictatorship. Until then, Mr. Gauck, who was 50 at the time, had lived his entire life in totalitarian systems, including his early life under the Nazis. “I will never miss an election,” he told the delegates, to applause.

Mr. Gauck, tall with gray hair and a sonorous voice, does not belong to a political party. He emerged last month as consensus candidate to restore a sense of respectability and authority to the office of the president. His predecessor, Christian Wulff, stepped down last month after being accused of accepting favors from business executives while he was governor of Lower Saxony State. Mr. Wulff had replaced Horst Köhler, who quit abruptly in 2010 after a media outcry concerning his remarks about possibly expanding the German military’s role abroad.