Chancellor Angela Merkel's party celebrated her 18 years as its leader with a lengthy standing ovation on Friday and then elected the successor who could help shape Germany's political direction for the next generation.

A close ally of Merkel's came out on top over a former rival of the chancellor in a close vote at the Christian Democratic Union conference in Hamburg.

CDU general secretary Annegret Kramp-Karrenbauer, 56, received 517 votes in a runoff. Friedrich Merz, once the party's parliamentary leader, received 482 votes.

Merkel announced in October she would give up the reins in her party, though she has said she plans to remain chancellor until the end of the current term in 2021. However, it's possible elections could be called before then.

The three high-profile contenders to succeed her spent the last month touring Germany to drum up support. Major German parties have tended to determine their leaders without a contest, and this is the first open competition for the CDU leadership since 1971.

Friedrich Merz, who ran against Kramp-Karrenbauer for the party chairmanship, delivers his speech during the party convention on Friday. (Markus Schreiber/Associated Press)

"We're a bit like the last unicorn in Europe — the last big people's party that still exists," Kramp-Karrenbauer told delegates before the vote. "I want that to be the case tomorrow too. This Europe, this Germany, this world needs a strong CDU."

Kramp-Karrenbauer won 450 votes in the first round on Friday, with Merz at 392 votes and health secretary Jens Spahn, a sometime Merkel critic, eliminated with 157 votes.

Kramp-Karrenbauer said after the vote "there is a place in this party" for Merz and Spahn.

We're a bit like the last unicorn in Europe — the last big people's party that still exists. - Annegret Kramp-Karrenbauer , new CDU party chair

In her pitch before the voting, Kramp-Karrenbauer, the party's general secretary and previously a popular state governor of Saarland, made much of her 18 years of experience in regional government. She said she has learned that leadership "is more about internal strength then external volume."

Kramp-Karrenbauer — often known as "AKK" — will be the favourite to run for chancellor in the next election, though that isn't automatic. She becomes only the eighth leader of the CDU since the Second World War. All but two of her predecessors served as chancellor.

Merz highlighted the need to tackle the "intolerable" success of the far-right Alternative for Germany (AfD) and called for a more combative approach to the CDU's rivals in the political centre.

Merz, 63, who advocates for a more conservative approach than Merkel, said that "without clear positions we won't get better election results."

Merkel has been CDU leader since 2000 and chancellor since 2005. She moved her party relentlessly to the centre, dropping military conscription, accelerating Germany's exit from nuclear energy, introducing benefits encouraging fathers to look after their young children and allowing the introduction of gay marriage.

German Health Minister Jens Spahn, by far the youngest candidate at 38 years old, couldn't get past the first round of voting. (Michael Sohn/Associated Press)

Most controversially, she allowed large numbers of asylum-seekers into Germany in 2015.

Merkel listed some of those moments and many more in a half-hour farewell speech as leader, telling delegates that "our CDU today is different from the year 2000, and that is a good thing." She also celebrated Germany's balancing of its budget in recent years and its response to the eurozone debt crisis.

Waning CDU support

For years, Merkel's popularity lifted the CDU and its Bavaria-only sister party, the Christian Social Union. In the 2013 election, they won 41.5 per cent of the vote and only just fell short of an outright parliamentary majority.

At present, the centre-right bloc is polling under 30 per cent. Merkel's fourth-term governing coalition with the centre-left Social Democrats has lurched through a series of crises since taking office in March, and the CDU has lost supporters both to the liberal Greens and the far-right AfD.

German Chancellor Angela Merkel gave her final speech as leader of the centre-right Christian Democratic Union during a party congress in Hamburg on Friday. (Fabrizio Bensch/Reuters)

Merkel, however, recalled that the CDU was in crisis when she took over in 2000, mired in a party financing scandal surrounding former chancellor Helmut Kohl.

"We kept a cool head," she said. "We showed everyone."

Merkel appealed to the party to show unity, noting that arguments in recent years over migration have showed "where endless arguments lead."

"I wasn't born as chancellor or as party leader," she said. "I have always wanted to do my government and party jobs with dignity, and one day to leave them with dignity."

In recent weeks, the new party leader sought to put a careful distance between herself and Merkel without disavowing her, saying she has had "very lively discussions" with the chancellor on various subjects.

Kramp-Karrenbauer has talked tough on immigration issues, proposing a lifelong entry ban to Europe for asylum-seekers convicted of serious crimes. But she has warned that endlessly rehashing debates about Merkel's decision to allow in large numbers of migrants in 2015 is a turn-off for voters.