On the third day of his state visit, the King laid a wreath at the ruins of St Nikolai church as a symbol of reconciliation.
The church was preserved as a memorial to the heavy air raids carried out by US and British air forces 80 years ago.
On Thursday, the King also made a speech about healing wartime divisions.
During the service on Friday, a choir sang and there were readings in the remains of the 19th Century church.
That included a reference to "remembering those who perished in the Allied bombing of Hamburg in 1943".
A display at the site recalls that 34,000 people died in a series of air raids in the intense bombing and firestorms that followed in the city in July 1943.
There was also a description of prisoners from a Nazi concentration camp who were forced to carry out the salvage and clearing operation after the raids.
King Charles laid a black and red wreath with the inscription "In everlasting remembrance" and the Queen Consort Camilla laid a white rose on the steps beside it.
They were accompanied by German President Frank-Walter Steinmeier, on a state visit that has sought to acknowledge the past but commit to a stronger future partnership.
The roofless church is now only a skeleton of its former self, but it had been designed by the English architect, George Gilbert Scott.
The same architect had designed the Albert Memorial in London, built in honour of the King's German ancestor Prince Albert.
But the high Gothic steeple of the church had been used as a navigation aid for bomber pilots and much of the church was destroyed.
Readings at St Nikolai spoke of setting grievances aside and avoiding the "hatred that divides nations from nations".
As with other parts of the state visit, there was tight security, with a police helicopter flying overhead as the choir sang.
The royal couple had travelled by train from Berlin to Hamburg, Germany's second-largest city - and on their arrival visited a memorial to the Kindertransport, in which thousands of Jewish children were rescued from the Nazis and brought as refugees to Britain.
There was also a visit to Hamburg's city hall and an event at which the King heard about efforts to develop green technologies.
This was the final day of a three-day state visit to Germany, the first of the reign of King Charles.
In speeches and events he delivered a message of needing to strengthen relations between Britain and Germany, against shared challenges such as the war in Ukraine and tackling climate change.