Aberdeen Grammar secured their status in the second tier of Scottish club rugby with a thrilling33-26 victory at Jed-Forest.
The win, coupled with Peebles' 45-29 defeat at Edinburgh Accies, ensured the Rubislaw club has escaped relegation with one game to spare.
It represents a remarkable turnaround for the Grammar players, who have won three games on the bounce since Ali O'Connor replaced Stuart Corsar as head coach.
Grammar travelled to the Borders in confident mood after a 29-17 victory against GHA and a 24-14 success against Stewart's Melville.
However, this was a tougher assignment against the side fourth in the table. but Grammar emerged victorious in an extremely close affair thanks to Grant Walker's late try.
O'Connor said: "It was a very happy dressing room after the game - it was a real thriller.
"Alex Hagart had a really good game with the boot and knocked over quite a few penalties in the first half.
"Peceli Nacamavuto scored a try, as always, and Conor Lavery scored from full back. But with three minutes to go, Jed came back at us and scored a try to level the game at 26-26.
"We thought a draw would be enough to take it to next week and get the points we required there.
"But the players strung a whole bunch of phases together and managed to score a try in the corner through Grant Walker to win the game and secure our future.
"We are absolutely delighted. Over the last three games the players have stepped up the intensity in training and what they are bringing to games. It has very much been player-led. Since I took over the application from the players gas gone through the roof.
"They are doing things we always new they were capable of, but have really produced it over the past couple of weeks so I am really pleased."
The victory moved Grammar two points clear of Peebles and seven ahead of Kelso, who will both drop[ down to National 2 next season having suffered defeats in their final matches of the season.
Grammar, who end the season against Howe of Fife this Saturday, can now start planning for next season in the second tier.
O'Connor said: "Everybody is delighted to stay where we are now but we realise we could have got more out of this season
"We went through a difficult patch between October and March.
"We will look to keep as many players as we can. Some might move away but we will start looking at the squad we will have for next season over the next couple of weeks."
Aberdeen Grammar: Conor Lavery; Grant Walker, Alex Ratcliffe, Peceli Nakamavuto, Martin McRobbie; Alex Hagart, Sam Knudson; Colin Neilson, Stuart Davis, Chris Prentice; Ali Mackie, Calum Champion; Christian Brew, Chis Jollands, Tony McGinness.
Replacements: Matthias Schosser, Graham Allan, Aaron Robertson, Doug Russell, Ali Addy.