Trains from Newcastle to Wollongong and across Sydney were due to lay dormant from Friday morning until Sunday night amid an escalating pay dispute between the state government and rail workers.
The largest rail shutdown in living memory would have caused commuter chaos and an estimated $50 million dent in the economy.
But late on Thursday, train guardspeople - ahead of Premier Chris Minns - announced a deal had been reached after last-minute talks with union heavyweights.
It involves the government agreeing to the union's demand to run trains 24 hours a day in return for no work bans.
But it won't involve all lines, with some to close overnight to enable track work.
Services were run around the clock last weekend to ward off stop-work bans.
Transport officials had tried to draw a line in the sand in recent days, stressing the maintenance disruptions made it unsustainable long-term.