King Charles III led a procession behind the queen’s coffin along Edinburgh’s Royal Mile on Monday as the cortege made its way to St Giles' Cathedral for a service of remembrance.
The king met mourners outside Holyroodhouse after arriving from London, where he addressed parliament for the first time earlier in the day.
He shook hands, accepted condolences and read floral tributes left for the queen, as officials waited to offer him the keys to Edinburgh.
The tune of God Save the King rang out around the city, before a 21-gun salute was fired and the king was invited to inspect the guard of honour.
The king was then reunited with his three siblings inside Holyroodhouse, including Princess Anne, the queen's only daughter, who accompanied the funeral cortege on its journey from Balmoral to Edinburgh.
Princes Andrew and Edward also took part in the sombre walk to St Giles' Cathedral, as the queen left her official Scottish residence for the last time.
They were all wearing military uniform except Prince Andrew, who was stripped of his royal titles following his involvement in a scandal linked to the paedophile Jeffrey Epstein.
They were accompanied by Princess Anne's husband Vice Admiral Sir Tim Laurence. Following in a car behind were Queen Consort Camilla and the Countess of Wessex.
The hearse was flanked by the bearer party and the Royal Company of Archers, the sovereign's bodyguard in Scotland, as it made its way slowly up the Royal Mile in front of a huge waiting crowd.
Members of the procession began to peel away as it rounded the corner to approach the Cathedral, coming to a stop below the steps.
The bearer party moved back into position before carrying the coffin out into the church.
The service was attended by members of the royal family, the UK Prime Minister Liz Truss, Scottish First Minister Nicola Sturgeon, and other officials and members of the public.
The cathedral choir sang Thou Wilt Keep Him in Perfect Peace, Whose Mind Is Stayed on Thee as the coffin was placed on a wooden catafalque.
The Crown of Scotland, first used by Mary Queen of Scots, was then placed on the coffin.
At the beginning of the service, the Rev Calum MacLeod welcomed the royal family and “people whose lives were touched by the queen in so many unforgettable ways”.
“And so we gather to bid Scotland's farewell to our late monarch, whose life of service to the nation and the world we celebrate. And whose love for Scotland was legendary,” he said.
The Rt Rev Dr Iain Greenshields delivered the homily: “These last few days, as tributes to Her Majesty have poured in and we have watched images of her on screen from her earliest years, capturing that remarkable life, yet now beginning to sink in that she is gone from us, 'gone home', to express her own words.
“We are united in sorrow at the death of our monarch, but we are also so aware that His Majesty King Charles and all his family are not just grieving the loss of their queen, but their mother, grandmother and great-grandmother.”
As the service ended, four members of the Royal Company of Archers, the king's ceremonial bodyguard unit in Scotland, began the first watch over the late queen.
Balmoral to Edinburgh
The procession arrived in Edinburgh on Sunday after making the six-hour journey from the queen's Scottish home of Balmoral, where she died late last week.
People came out in cities and rural areas, where farmers parked their tractors side by side and horse riders gathered to pay their respects.
The final stop was Holyroodhouse, where the queen’s coffin was placed in the throne room to lie at rest before today’s service.
Crowds more than 10 deep lined the Royal Mile in the early afternoon sunshine, awaiting the procession.
The queen had a deep connection to Scotland, which she visited each summer, and she referred to the 72,000-acre Balmoral estate as her “second home”.
She carried out her first royal duties in Scotland in Aberdeen in 1944 when she was just a teenager and yet to ascend to the throne.
She completed her final duties just two days before her death, inviting the new prime minister, Ms Truss, to form a government.