St Johnstone manager Craig Levein said he had to "take an extra couple of heart tablets" after his side avoided the Scottish Premiership relegation play-off by beating Motherwell on a dramatic final day.
Levein's side needed to win and rely on Ross County failing to do the same at home to Aberdeen and, though that transpired, the afternoon was not short on twists and turns.
St Johnstone started the day heading for 11th before ending their game with a tense wait as their survival on goal difference was confirmed.
"I'm delighted and extremely stressed out," Levein, who had a heart attack in 2018, told BBC Scotland.
"When the Motherwell fans celebrated after the game finished just to wind us up, I had to take an extra couple of heart tablets.
"I've never really been in a relegation battle as a manager. It was a bit stressful and there was a lot of cajoling, some pats on the back and stern words at times to get the players into the position where they're surviving.
"All credit to them, I thought they were fantastic today."
With County leading Aberdeen early, Nicky Clark made sure St Johnstone at least started holding up their end of the bargain by sliding to steer home Graham Carey's wonderful cross.
Then 16 seconds of drama turned the tide when former St Johnstone striker Theo Bair had his penalty saved by Dimitar Mitov, as Aberdeen drew level in Dingwall.
With St Johnstone now heading for safety, their situation was bolstered by Adama Sidibeh, who took advantage of a Motherwell mix up to nod in a second goal before the break.
The second half was more about holding off a resurgent Motherwell with the brilliant Mitov, Ryan McGowan and Liam Gordon producing fantastic blocks to keep the home side out.
St Johnstone were strengthened by the knowledge Aberdeen had gone ahead against Ross County, but a red card and a Yan Dhanda penalty meant Don Cowie's side had nearly half an hour to find a winner against 10 men.
But Levein's men finished to job at Fir Park despite a late Moses Ebiye goal for Motherwell, and nervously waited on news from the Highlands.
When the result was confirmed, the players and fans celebrated wildly as they finished 10th on goal difference.
Player of the match - Adama Sidibeh (St Johnstone)
Saints clinch unlikely survival - analysis
St Johnstone were heading straight for the play-off with Raith Rovers up until the 90th minute on Wednesday, and come Sunday evening they were celebrating a 16th straight season in the top flight.
A side that has toiled for goals and produced a largely insipid end to the season with one win in their last nine before the final game, burst to life at Fir Park.
All their big players stepped up. From Mitov in goals saving Bair's penalty, to captain Liam Gordon producing the block of the season on the line, and Carey and Clark getting things going with a terrific first goal.
Sidibeh has proved a massive signing having come up with goals in the crucial final two games.
Credit to Levein, who was brought in with Saints bottom of the table in the autumn and tasked with keeping them up.
It wasn't pretty, but he did it. Even the switch to a back five in the second half stemmed Motherwell's fight back. They'll hope for better next season amid a change of ownership and three difficult seasons battling the drop.
But for now they can enjoy their achievement, and their holidays.
Motherwell had nothing to play for here except eighth place, and they end the season ninth.
It's been a mixed campaign filled with lots of goals, with Stuart Kettlewell's side proving themselves capable of scoring plenty, but conceding too many too.
Their home form has been a source of frustration, but their away form a positive. In essence it's been an inconsistent campaign from the Steelmen.
The loss of Blair Spittal - who got 13 goals and 11 assists - and others such as Georgie Gent means Kettlewell will have work to do on a tight budget to build a competitive squad for next campaign.
But in the depths of winter when they went 15 without a win, they would have settled for comfortably staying in the league.
What they said
Motherwell manager Stuart Kettlewell: "I'm trying to stay as positive as I can. I really wanted to go out on a high and get a performance and result that keeps everyone over the summer.
"But on reflection we found ourselves in a really tough spot this season. We showed a lot of personality and a lot of character. We scored as lot of good football and scored goals to get us back into a more comfortable position."
St Johnstone manager Craig Levein: "It was a good performance by the boys today we deserved to win. We've been good the last week or so in the last three games.
"We've managed to get ourselves in the position we'll be in the Scottish Premiership next year.
"We had a lot of good performances today. There were a couple of minutes we had to defend manfully to stop Motherwell getting their first goal."