Speaking at the historic "Matthiae-Mahl" banquet, Merkel insisted, to thunderous applause, that continued UK membership was not only in Germany's interest, "but also in Britain's and in the interests of the entire EU".
The banquet's host, Hamburg mayor Olaf Scholz, said Britain was "irreplaceable" in European foreign and defence policy.
"And from an economic point of view, too... we can't and won't do without London," he added.
Scholz, a member of the Social Democrat SPD party which shares power with Merkel's conservative CDU, said Britain needed to show "pragmatism and courage... and their ability to compromise."
Drawing an analogy to football, he said that "the British alone will decide what the result will be, whether the ball is in or out. And this time, we're all hoping the decision will be: In."
Cameron expressed confidence that a deal could be reached which would allow Britain to remain in the European Union and avoid a so-called "Brexit".
"When it comes to the question of Britain's place in Europe, I have always been confident that together we can secure the reforms that address Britain's concerns and also work for Europe as a whole," Cameron told the banquet, where he was guest of honour alongside Merkel.
Britain has "always been a country that reaches out," he said. "And I never want us to pull up the drawbridge and retreat from the world. So when it comes to the question of Britain's future in Europe, my aim is
clear: I want to keep Britain inside a reformed European Union."
"If by working together we can achieve these changes, then I will unequivocally recommend that Britain stays in a reformed European Union on these new terms."
Story continues below…
Cameron is engaged in an intensive round of high-stakes diplomacy aimed at renegotiating the terms of Britain's EU membership before holding an in-out referendum.
He must convince his 27 fellow EU leaders to back the controversial reform proposals at a leaders' summit in Brussels on February 18-19.
He said that if no deal was reached, "then I rule nothing out. But I believe we can -- and if we do, I believe we can win that referendum and that will be good for Britain, good for Germany and good for the whole of Europe.