German Chancellor Angela Merkel has given an emotional farewell speech to her ruling Christian Democrats (CDU), as she steps down as party leader.
She was speaking at a special party conference to elect her successor. She plans to stay Chancellor till 2021.
Her preferred choice, Annegret Kramp-Karrenbauer, is in a run-off with millionaire lawyer Friedrich Merz.
The former chief minister of Saarland received 450 votes to Mr Merz's 392 in a first round of votes on Friday.
A third candidate, health minister Jens Spahn, received only 157 of the 999 votes cast in CDU's party conference in Hamburg.
Counting from a second round of voting is now under way.
Ms Merkel plans to serve out her full term as chancellor.
Ms Merkel's speech was punctuated by applause and she got a standing ovation of more than six minutes at the end. CDU delegates at the congress in Hamburg also held up signs saying "Thanks boss".
Then the conservative party paid tribute to Ms Merkel, 64, with a video showing highlights from her 18-year CDU leadership. The soundtrack was the 1960s hit Days, by The Kinks.
Ms Merkel was first elected chancellor in 2005 and is not seeking a fifth term beyond 2021.
In her speech she warned of tough challenges ahead, including climate change, maintaining European unity and coping with Brexit.
She reminded the CDU of other electoral successes last year, avoiding mention of this year's setbacks in state elections, which were heavy blows for her.
"I don't need to be party chairman to remain bound to this party. And I'm still chancellor," she said.
She stressed that the CDU stood for human dignity, and praised the late US President George Bush Senior and late German Chancellor Helmut Kohl for reuniting Germany in 1990. She was at the funeral of George HW Bush on Wednesday.
Speaking of the end of the Cold War, she told the CDU that "at that decisive time he [Mr Bush] trusted Chancellor Kohl... he understood how politics must serve everyone".
She expressed "overwhelming gratitude" for having had the role of CDU leader. "The future will test our values... we must always approach work joyfully," she said.
Who wants Merkel's job?
Annegret Kramp-Karrenbauer - known as AKK, the Merkel choice
The 56-year-old former prime minister of the state of Saarland was appointed CDU general secretary earlier this year and is the party favourite, polls suggest. Popular in Saarland and Berlin, she has an unpretentious style and a reputation for calm analysis, as well as political acumen.
Her greatest strength is also her greatest weakness; she is a Merkel loyalist, perceived as someone who will replicate much of the chancellor's style and policy.
The millionaire businessman was a powerful player in the CDU in the early 2000s but left politics when he fell out with the chancellor.
Since then the 63-year-old lawyer - who has strong links to America - has built a career in the private sector and works for US investment firm Blackrock. He appeals to the more conservative and business-minded wing of the party and has the official backing of ex-Finance Minister Wolfgang Schäuble.
The health minister is ambitious and, aged 38, the youngest of the three candidates.
A former banker, he was once described by Mr Schäuble as "one of the great hopes for the future of our party".
But Mr Spahn has ruffled feathers in the party and in the cabinet. Sharply conservative, Catholic and gay, he is a divisive figure for many.