The installation of the 30-mile Borders railway has been completed.
Transport Minister Keith Brown clipped the final length of rail into place after arriving at Tweedbank station on the first train to reach the end of the new line.
The new railway will re-establish passenger services for the first time in more than 40 years from Edinburgh through Midlothian to Tweedbank in the Borders.
It is due to enter service from September this year, allowing people to travel from the capital to Tweedbank in around an hour at peak times.
Since track-laying commenced in October last year, more than 1,000 rails have been laid across more than 90,000 sleepers using a specialist rail installation machine, making it the longest new domestic railway built in Britain in over a century.
Further work on installing signalling and communications equipment and completing the construction and new stations at Shawfair, Eskbank, Newtongrange, Gorebridge, Stow, Galashiels and Tweedbank will now go ahead.
Mr Brown said: "It is a huge honour to put the final piece of track in place and travel on the first train to run into the Borders in almost half a century.
"The reopening of this line offers a once in a generation opportunity to deliver a major economic and social boost for the communities it will serve.
"In just a few short months, trains will be carrying passengers to employment, social and study opportunities, as well as bringing visitors and investors to the communities all along the route.
"We can expect the Scottish economy to benefit by tens of millions of pounds from its reopening and the area around the railway line will be an exceptional tourist destination, with a steam railway service, National Mining Museum Scotland, world-class exhibition spaces, and the Great Tapestry of Scotland displayed at Tweedbank."