A major clear-up operation is under way after torrential rain caused severe disruption to commuters.
The main rail line from Edinburgh to Glasgow was shut after flooding at Winchburgh tunnel in West Lothian resulted in passengers on five trains being trapped for several hours.
ScotRail said engineers had been working through the night to pump 2ft of water from the tunnel.
NetworkRail aims to have the line open for early-morning commuters on Friday.
It said engineers would be sent in to check the tunnel and signalling system for damage caused by the flood before it gets the all-clear.
The issue is continuing to affect rail services across the central belt.
ScotRail said water levels were "falling slowly" and thanked crews from the Scottish Fire and Rescue Service who joined efforts on Thursday.
It tweeted: "Once the water's cleared, engineers will need to ensure that the tunnel is safe for use. This will involve a thorough inspection and an empty train being driven through to test the lines."
The Scottish Fire and Rescue Service has deployed a high-volume pump to help Network Rail tackle the flood in the 340m-long tunnel. The pump can remove 7,000 litres a minute.
Rail passengers travelling between Glasgow and Edinburgh are being advised to make alternative arrangements for travel and to check ahead before setting off on journeys.
Suz Scott was among passengers stuck on one of the five trains stranded in floodwater outside Linlithgow.
Further footage of the conditions inside the Winchburgh Tunnel at the moment. @NetworkRailScot's team remain on site. Pumps are running, but a massive amount of rain has fallen and needs to be cleared. ^CT pic.twitter.com/atOuxORgnj— ScotRail (@ScotRail) August 7, 2019
She told the BBC Scotland website that there was an announcement that there was too much water ahead and behind the train to continue their journey.
"Then we saw this deluge of water start to submerge the tracks," she said.
The "poor train staff" were trying to find a solution to the problem but did not seem to have a "plan B", she added.
The rail firm later tweeted to say the Glasgow-bound stranded trains would return to Edinburgh due to the depth of the water in the Winchburgh tunnel.
Replacement bus services have been put in place between Linlithgow and Falkirk Grahamston to Edinburgh Park.
The wettest spot in Scotland
Edinburgh/Gogarbank was the wettest spot in Scotland on Wednesday, with 36mm of rainfall.
This was for a 12-hour period from 07:00 to 19:00, but most fell between 16:00 to 19:00. The total included 13.4mm between 16:00 and 17:00. The nearby site of Murray Burn recorded 19mm in one hour.
There was 27mm of rain at Lossiemouth for the same 12-hour period, with 11mm falling between 15:00 and 16:00.
Drumnadrochit recorded 24mm in 12 hours, of which 15mm fell in the hour from 17:00 to 18:00.
The village of Dipple in Moray saw 69.4mm in the 36 hours up to 13:00 on Thursday - which is the local average for a month.
The heavy rain also caused problems around Edinburgh Airport on Wednesday evening, with access roads flooded and cars stuck in floodwater.
Cars and buses were unable to access the airport for a time after the approach road from the M8 motorway came under several feet of water.
A man was spotted cycling through flood water at a roundabout just off Eastfield Road, as the rain water left vehicles on the road partially submerged.
Police in Fife warned drivers to take care as water levels reached up to car bonnets on Admiralty Road, Dunfermline.
A spokesperson posted on social media: "Some serious rain out there causing widespread flooding and awful driving conditions across the south west Fife area.
"Please drive with care, switch your lights on and leave a large gap between the vehicle in front."
The Met Office has issued a yellow warning for further heavy rain and thunder storms for much of the UK on Friday.
Meanwhile, part of a railway route in the west of Scotland will remain closed until 22 August after severe flooding swept away part of the track.
The decision was taken to keep the line closed between Ardlui and Crianlarich following detailed geotechnical and aerial surveys of the damage.
However, services will be reintroduced between Crianlarich and Oban from Monday.