BARACK Obama received a rock star welcome in Berlin as he appeared at a public debate with Chancellor Angela Merkel, whom he praised as one of his "favourite partners" during his presidency.

Security was tight in front of the German capital's iconic Brandenburg Gate, where former US leader Obama and Merkel appeared on a podium before thousands of people attending a gathering marking the 500th anniversary of the Protestant Reformation.

Police helicopters patrolled the skies and snipers with balaclavas watched the scene from nearby rooftops.

After lauding Merkel as someone who had done "outstanding work", Obama launched a defence of his own presidency and the values of liberal democracy championed by both leaders.

Citing the rise of nationalism and xenophobia in parts of the world, Obama told the crowd that "we have to push back against those trends that would violate human rights or suppress democracy or restrict individual freedoms".

In a veiled reference to his successor Donald Trump, Obama also spoke of the need to see development aid and diplomacy as essential aspects of national security policy.

"We can't isolate ourselves. We can't hide behind a wall," he said, to cheers from the audience.

Merkel, who hosted Obama at the same spot four years ago, was due to travel to Brussels later for a meeting with leaders of fellow Nato member states, including Trump.

The appearance with Obama was criticised by some German opposition politicians as a publicity stunt ahead of September's General Election, in which Merkel aims to win a fourth term.

At the beginning of their discussion, Obama praised Merkel to the excited cheers of a crowd of young Protestants, who had travelled from all over Germany and beyond to attend the religious gathering.

"Not only do I love this city, but one of my favourite partners throughout my presidency is sitting next to me," Obama said.

"Chancellor Merkel has done outstanding work, not just here in Germany, but around the world."

After lauding Merkel, he launched a defence of his own presidency and the values of liberal democracy championed by both leaders.

The former US president and the German chancellor, who grew up in a pastor's household in East Germany, chatted about their faith and called on the youth to commit to helping make the world a better place — while keeping in mind that change does not come quickly from one day to the next.

Referring to the terror attack in Manchester, Obama said that he and the chancellor were "heartbroken about the loss of life ... and that it's a reminder that there is great danger and terrorism and people who want to do great harm to others just because they're different".

Despite describing the world as "a very complicated place," Obama and Merkel still found time to joke with each other and made the crowd laugh several times.

The harmony and ease between the two leaders was a stark contrast to Merkel's meeting with Donald Trump in Washington in March, when the US president appeared to refuse to shake Merkel's hand in front of reporters.

Trump has said he did not hear a reporter calling for a handshake.

Merkel, who hosted Obama at the same spot four years ago, was due to travel to Brussels later on Thursday for a meeting with Trump and leader of other Nato-member states.