Warrenpoint Town have been relegated from the Irish Premiership after dramatic finishes to the two key games.
Carrick Rangers, who started the final day bottom of the table, scored two late goals to beat Ballinamallard United 2-1.
That win lifted Gary Haveron’s men out of the bottom as Warrenpoint were denied victory away to Dungannon who equalised after a disputed penalty.
Ballinamallard will face Championship side Institute in the play-off.
Institute are at home in the first leg on 6 May and then travel to Ferney Park for the return four days later.
Cruel end for Warrenpoint
Warrenpoint would have been out of the bottom two and safe if Dungannon had not snatched a controversial equaliser at Milltown.
Trailing 1-0 through a Stephen Hughes goal, Dungannon were awarded a 90th-minute penalty after Warrenpoint’s Jordan Dane collided with opponent Cormac Burke.
Referee Ross Dunlop pointed to the spot but it looked a highly dubious decision and Warrenpoint’s players were clearly furious, convinced they should have been awarded a free-kick.
Ryan Harpur’s penalty was saved by keeper Jonathan Parr but, after several blocked attempts, Andrew Mitchell forced in the equaliser.
Carrick’s great escape
Carrick Rangers had seemed destined for automatic relegation as they trailed to a 42nd-minute strike by Ballinamallard’s former Northern Ireland international Ivan Sproule.
But Mark Surgenor scored an 89th-minute equaliser and Miguel Chines snatched the unlikely win with an overhead kick in stoppage-time.
So, in the space of a few minutes, Carrick’s fortunes were turned on their head.
“It is unbelievable, we took it right to the wire,” said Carrick manager Gary Haveron.
“For us to keep ourselves in the Premiership, on the limited resources we have, is fantastic and all credit to the players.”