The Queen has officially opened the new Borders-to-Edinburgh railway line on the day she became Britain's longest-serving monarch.
She and the Duke of Edinburgh were accompanied by First Minister Nicola Sturgeon on a steam train journey along the £294m line.
Crowds in Tweedbank heard the Queen thank people around the world for their "touching messages of kindness".
She also said she had never aspired to be on the throne for so long.
The Queen added: "Inevitably a long life can pass by many milestones. My own is no exception. But I thank you all and the many others at home and overseas for your touching messages of great kindness."
Specially-selected passengers got a sneak preview of the route, the UK's longest domestic line to open in a century, on Saturday.
The line between Tweedbank and the capital was publicly-opened on Sunday.
People had lined the streets of Edinburgh as a procession made its way to the city's Waverley Station to meet the Queen, whose helicopter touched down at Holyrood Palace shortly before 11:00.
By Philip Sim, BBC Scotland reporter
Crowds started gathering at Waverley Station hours in advance of the Queen's arrival.
Some had come from as far afield as Australia and Canada in the hope of catching a glimpse of the monarch on her historic day.
There was a festival atmosphere at the station, with a guard of honour on the platform, a pipe band performing, a chocolate model of the Flying Scotsman on display and everything from railings to dogs bedecked with union flags.
Commuters, tourists and well-wishers alike thrust flags, camera phones and occasionally children into the air as the procession of honoured passengers marched by, eagerly awaiting the arrival of the royal motorcade.
The train itself, the Union of South Africa, was as much a focus of attention as anything else, the steam locomotive providing the backdrop for a succession of selfies.
There were cheers and cries of "congratulations" from the crowd as the Queen stepped out of her car and was greeted by the first minister, who had earlier earned the envy of a crowd of watching enthusiasts by climbing into the engine's cab.
After a quick wave to the crowds, the royal couple were quickly aboard the train and, amid a puff of steam and blast of the whistle, were off on a landmark journey to the Borders.
The royal party's arrival in Edinburgh had been delayed by about 40 minutes due to poor weather at Balmoral.
The National Youth Pipe Band of Scotland entertained the crowds as they patiently waited for the guest of honour.
The Queen was welcomed at Waverley Station by First Minister Nicola Sturgeon before embarking on the historic railway journey.
Dozens of invited guests joined them on board the Union of South Africa as it made its way to Tweedbank.
Buckingham Palace has calculated Queen Victoria reigned for 23,226 days, 16 hours and 23 minutes.
The Queen passed that record at 17:30.
The royal party had left Edinburgh at 11:15 and stopped off for a walkabout in Newtongrange, where it was greeted by flag-waving crowds.
The Queen arrived at the Tweedbank terminus for the ceremony just after 13:00.
First Minister Nicola Sturgeon paid tribute to the Queen as she prepared to open the railway.
Ms Sturgeon said it was "a privilege" that the Queen had chosen to mark the day she becomes the UK's longest-serving monarch with a visit to Scotland.
She added "a simple but heartfelt thank you" from everyone around the world who wanted to congratulate her on her anniversary.
By Giancarlo Rinaldi, South Scotland reporter
The crowds gathered early in the Scottish Borders for the royal opening of their rail link to Edinburgh.
Under grey skies, spectators filtered through Tweedbank to their brand new station to catch a glimpse of the Queen.
The line has been open to the public since Sunday but the regal trip along the route was set to give it the official stamp of approval.
There was a little groan from some of the flag-carrying public when it was announced that the Queen was running late due to fog.
But, having waited 46 years for the return of their railway, an extra hour or so did not seem such a great inconvenience.