Those who live in London are routinely accused of failing to make the most of the capital's historic attractions. Not so the Queen. By early yesterday afternoon, she had fitted in not only a service to mark 300 years of St Paul's Cathedral but also a belated birthday lunch at Downing Street to celebrate 90 years of another venerable British institution: the Duke of Edinburgh.

Before making their first visit to No 10 for more than a decade for a lunch of Stilton and watercress tart, Aberdeenshire beef and peaches and nectarines with ice-cream, the royal couple visited Sir Christopher Wren's masterpiece to see for themselves the results of a mammoth spruce-up.

Over the past 15 years, at a cost of £40m, every inch of stone, mosaic, wood and metal has been cleaned inside and out so that the cathedral gleams once again.

During three centuries of jostling for status with Westminster Abbey, St Paul's has been the setting for some grand occasions.

They include the jubilee celebrations for Queen Victoria, services to mark the end of the first world war and the second, which it barely survived, the first wedding of Prince Charles and the funerals of Winston Churchill, the Duke of Wellington and Admiral Lord Nelson.

The dean, the Right Reverend Graeme Knowles, said in his sermon: "The much overworked word 'iconic' has been used to describe the dome, and no one could fail to recognise its silhouette. The wartime photographs of the dome rising unscathed above the smoke and fire of the blitz can be found everywhere."

Work was officially completed in June 1711, although it was made clear in a service which matched glorious music, solemn prayers and unexpectedly entertaining readings, that the story is slightly more complicated than that.

Old St Paul's, on a site where a church had stood at least since AD604, burned down in the great fire of London. Surveyor to the Fabric Martin Stancliffe, who oversaw the huge restoration job, read out John Evelyn's dazzling report of the scene. On 7 September 1666, Evelyn wrote: "It was astonishing to see what immense stones the heat had in a manner calcined, so that all the ornaments, columns, friezes, capitals and projectures of massy Portland stone, flew off, even to the very roof ... Thus lay in ashes that venerable church, one of the most ancient pieces of early piety in the Christian world".

Wren is said to have laid the first stone on 21 June 1675, the summer solstice, a date that would have had significance for the astronomer-architect. By 1694 Evelyn had visited the completed choir: "A piece of architecture without reproach."

On 5 December 1698 – despite an earthquake in Dorset preventing stone deliveries – the first Sunday service since the fire was held. In 1705 Queen Anne attended a service of thanksgiving for the battle of Blenheim. Six years later poor Wren was still petitioning parliament for the balance owed of half his salary. They finally voted that he should be paid in December 1711. Since he was due the money six months after the work was completed, the job was officially declared to have been finished in June 1711, the date duly celebrated in this royal anniversary service.

The dean invited the congregation to admire some of the more lamentable monuments inflicted on posterity: Samuel Johnson looking ridiculous in a toga, Nelson with a sagging lion apparently barely able to keep its eyes open, Sir John Moore being lowered by classically draped muscle men into a sort of giant marble bath. In contrast, Wren is commemorated by the tremendous epitaph composed by his son, set into the marble floor: "Lector si monumentum requieris, circumspice." (Reader, if you seek a monument, look around you).

"What better monument could a man leave behind him, other than a cathedral which has come to represent the presence of God at the heart of this amazing city?" the dean asked.

As the congregation left, an invisible film of the dust from 6,000 shoes and breath from 6,000 lungs was settling over the gleaming interior. In a few decades the cleaning will have to start all over again.