The RAF C-17 took off from Edinburgh Airport in late afternoon sunshine and a largely cloudless sky at 5:43pm after her cortege had travelled from St Giles’ Cathedral in the Royal Mile.
It came after 33,000 people filed past the Queen’s coffin to pay their respects as it lay at rest in the church overnight.
Accompanying the coffin on the Queen’s final flight – to RAF Northolt in London – was the Princess Royal and her husband Vice Admiral Sir Tim Laurence, who had followed the hearse in another car.
The former sovereign’s 50-minute journey to the airport took her appropriately via Queensferry Street and Road, sections of which saw well wishers tightly packed behind barriers on both sides of the carriageway.
At one point on Queensferry Road, a steward in a fluorescent jacket was seen wiping her eyes after the coffin passed.
Beside the aircraft, eight RAF pall bearers wearing white gloves inched from the hearse, the corner of the Royal Standard draped over the coffin flapping in the breeze.
Assisted by a ninth colleague, they carried the coffin up the ramp into the huge cargo aircraft with a guard of honour from the Royal Regiment of Scotland in position close by.
As the aircraft's steps were retracted and it prepared to depart, the regiment's band played a single verse of the National Anthem.
First Minister Nicola Sturgeon, who was among political leaders to see the Queen depart from the airport, said: “Scotland has now bid our Queen of Scots a sad, but fond farewell.
"We will not see her like again.
“Over these past few days we have seen just how much Her Majesty meant to the people of Scotland.
“As anticipated, people from all walks of life gathered across the country and in our capital city to pay tribute to the only monarch most of us have ever known.
“The scenes on Sunday as Her Majesty’s cortege made the journey from Balmoral Castle to the Palace of Holyroodhouse, and then yesterday and today as thousands gathered along the Royal Mile and queued to enter St Giles to see the Queen’s Coffin, will forevermore form a very special part of the history of Scotland.”
Ms Sturgeon paid tribute to “the many public servants who have worked tirelessly in recent days and over many years to develop and, when the time sadly came, implement Operation Unicorn”.
She said it had involved thousands of staff from the emergency services, local authorities, armed forces, volunteer networks, transport and government agencies.
She said: “The events of recent days have provided a sincere, solemn and fitting tribute from the people of Scotland to Her Majesty The Queen.”
The operation had been planned for years, but a source close to the organisers told The Scotsman the preparations were ramped up when it become clear that the Queen was likely to end her days at Balmoral this summer.
They said: “It was suspected she would pass away there when she started pulling out of events.
"The Scottish Government called for volunteers to help out from among its own staff which has never been seen before, even for COP26 [last year’s huge United Nations climate change conference in Glasgow].
"It wasn’t a panic but a call to arms.
"From the beginning of the summer, people were pulled from other projects and pretty much everything else was dropped.”
The source said one of the biggest challenges had been being prevented by Royal officials from publishing details of the cortege route and timings from Balmoral to Edinburgh until 5pm on Saturday - giving the public just 17 hours’ notice.
They said: “With COP26, there were months of publicity about the likely travel disruption, but we were left with only a really small window to publicise the plans.
"Luckly, drivers were courteous, patient and kind.
"The public’s behaviour was broadly brilliant, with hardly any arrests and only a few incidents, like a couple of people running across a motorway, which were quickly nipped in the bud.
"That's pretty amazing over a 170-mile route with things like kids being held over bridge parapets.”
Officials were also relieved that onlookers heeded warnings not to throw flowers or objects like teddies at the hearse.
The source said: “It sounds petty, but that was to prevent delays to the roads re-opening if they had to be cleared first.”
Fewer people than expected lined the route – an estimated 150,000-170,000 compared to the projected 175,000-250,000.
The source said: “In built-up areas it was really busy but other parts of the route were quieter than predicted.”
However, a late decision to close streets in Edinburgh for the cortege’s journey to the airport was expected to cause more disruption than the previously-planned “holding stops” to traffic while the convoy passed.
There had also been concerns that large crowds would gather at Waverley Station in Edinburgh for the Queen's departure south, because previously-revealed plans would have seen her being conveyed to London aboard the Royal Train.
However, it is understood these were changed about 18 months ago because of concerns about the potential for large crowds during the Covid pandemic and it was decided the coffin would be transported by air instead – but this was not revealed until after her death.
The source said finalising the Queen’s journey from Balmoral in the days after her death on Thursday had been “some achievement”, involving officials from Police Scotland, Transport Scotland and councils.
They said: “There was a clear communications structure with defined roles which everyone stuck to, which hasn’t always happened in the past.
"This time it worked well.”