The Dean of Windsor paid tribute to Prince Philip’s “unwavering loyalty to the Queen” and “service to the nation”.
The congregation wore masks and was socially distanced in line with Covid rules, with the Queen seated alone.
Ahead of the service, the duke’s children walked behind his coffin in a funeral procession and there was a national minute’s silence.
His coffin was carried the short distance to St George’s Chapel on a modified Land Rover, which the duke himself helped to design.
Princess Anne and Prince Charles made up the front row behind the vehicle, followed by Prince Edward and Prince Andrew.
In the third row, Prince William and Prince Harry walked either side of their cousin Peter Phillips.
More than 730 members of the armed forces took part in the event, but there was a limit of 30 mourners inside St George’s Chapel, under coronavirus rules.
The funeral procession from the castle to the chapel was headed by the Band of the Grenadier Guards, the Major General’s party, and military service chiefs.
Vice Admiral Sir Timothy Laurence and the Earl of Snowdon also walked behind the coffin, trailed by members of the duke’s household staff.
The Queen, 94, travelled with a lady-in-waiting in the state Bentley at the end of the procession.
A ceremonial gun fire at nine locations across the UK, and in Gibraltar, marked the start and end of the national minute’s silence.
No planes landed or took off at Heathrow for six minutes to coincide with the silence and all major sporting events were rescheduled to avoid a clash with the funeral.
The funeral service was conducted by the Dean of Windsor, with the Archbishop of Canterbury pronouncing the blessing.
Buglers of the Royal Marines sounded Action Stations – a signal that all hands should be ready for battle – as the coffin was lowered into the Royal Vault at the end of the service.
The Dean of Windsor paid tribute to Prince Philip’s “kindness, humour and humanity” and the “many ways in which his long life has been a blessing to us”.
“We have been inspired by his unwavering loyalty to our Queen, by his service to the nation and the Commonwealth, by his courage, fortitude and faith,” he said during his bidding.
The duke’s association with the Royal Navy and love of the sea was also a focus of the service but no sermon was delivered, in line with his wishes.
The music included the 1860 hymn Eternal Father, Strong to Save, by William Whiting, which is associated with seafarers and the maritime armed services.
There was a reduced choir of four singers but the congregation did not sing, in line with coronavirus restrictions.
Buckingham Palace said the funeral plans had been modified to take into account public health guidelines.
The funeral took place entirely within the grounds of the castle and the public were asked not to gather there or at other royal residences.
But the ceremonial aspects of the day and the service remained in line with Prince Philip’s wishes and reflected his military affiliations and personal elements of his life.
Ahead of the funeral, the Queen shared a favourite photograph of herself with the Duke of Edinburgh, showing the couple in Aberdeenshire.
Taken by the Countess of Wessex in 2003, the picture shows the couple relaxing on a picnic rug on the grass at the Coyles of Muick beauty spot, near the Queen’s private estate of Balmoral.
The 30 guests at the funeral wore morning coats with medals, or day dress, but not military uniform.
The Queen and duke’s four children – the Prince of Wales, the Princess Royal, the Duke of York and the Earl of Wessex and – as well as their eight grandchildren – attended, but none of their young great-grandchildren.
Spouses of the children and grandchildren are among the congregation, including two who have married into the family in recent years – Jack Brooksbank and Edoardo Mapelli Mozzi, husbands of Princesses Eugenie and Beatrice.
But the Duke of Sussex’s wife, Meghan, is heavily pregnant and was advised by her doctors not to fly in from the US. She was said to have watched the service from home.
The other mourners included the children of the Queen’s sister, Princess Margaret, and three of Prince Philip’s German relatives – Bernhard, the Hereditary Prince of Baden; Donatus, Prince and Landgrave of Hesse; and Prince Philipp of Hohenlohe-Langenburg.