Almost 90 jobs were at risk after bus operator First Scotland East announced it was withdrawing services in East Lothian.
In May 2016, First Group revealed plans to stop bus operations in the area from 14 August 2016.
It also proposed closing its depots in North Berwick and Musselburgh.
The firm had blamed "an increasingly competitive market".
An agreement has now been reached which will see East Coast Buses Ltd, a wholly owned subsidiary of Lothian Buses Ltd, buy the Musselburgh and North Berwick depots with all staff having the option to be transferred.
The buyer has also announced plans to improve services and increase the number of vehicles.
Richard Hall, managing director of Lothian Buses, said: "We are pleased to be in a position to take on and continue providing these vital services and be part of the local economy."
Paul McGowan, managing director of First Scotland East Ltd, said: "I'd like to thank all my colleagues in East Lothian for their hard work and loyalty over the years."
He added: "We will be fully supporting them as they transfer to their new employer."
Threatened East Lothian bus services and jobs have been saved as part of a new takeover package from Lothian Buses Ltd.