The Waverley line through the Borders closed in 1969
MSPs have approved the bill to restore the Borders rail link between Edinburgh and Tweedbank near Galashiels.
Work on the £155m project is expected to start shortly and the line is scheduled to open in 2011.
An attempt to have the 35-mile (56 km) line built in stages was overwhelmingly rejected by MSPs.
Critics accused Labour MSP Bristow Muldoon of a wrecking manoeuvre, which would have resulted in the line going no further than Midlothian.
MSPs approved the Waverley Railway (Scotland) Bill by 114 votes to one, with one abstention.
The new railway line will run from Newcraighall in Edinburgh and will have stations at Shawfair, Eskbank, Newtongrange, Gorebridge, Stow, and Galashiels, before reaching the end of the line at Tweedbank.
'Righting a wrong'
An amendment to remove the building of a station at Stow from the project also came to nothing.
Lib Dem MSP for Tweedale, Etterick and Lauderdale Jeremy Purvis said the parliament was "righting a wrong done by Westminster" when it approved the closure of the Waverley line almost 40 years ago.
Other MSPs hoped that in time the restoration of the Waverley route would continue to Carlisle.
The village of Stow will get a station on the line
Tory MSP Ted Brocklebank was one of the MSPs who rejected the argument for reconstructing the line in stages.
He said: "A phased approach to constructing the railway would be more expensive and would be against the will of this parliament."
Green MSP Chris Ballance described Mr Muldoon's proposal as "a wrecking amendment designed to stop the railway at Gorebridge".
Transport Minister Tavish Scott told MSPs that the executive did not support Mr Muldoon's amendment.
He said that the Labour/Liberal Democrat partnership agreement commitment was to support the whole of the Borders railway being built.
Mr Scott told MSPs the executive had committed an estimated £155m towards the project.
The minister said: "The whole of the railway is justified not solely on the grounds of its economic benefit but also on the grounds of both social inclusion and improving accessibility to the Borders."
SNP Mid Scotland and Fife MSP Tricia Marwick, the convener of the committee which scrutinised the railway proposals, said it had unanimously backed the view that "the railway, if constructed, must go all the way to Tweedbank and serve the Borders community".