Last updated on .From the section Scottish Premiership

St Mirren face a Scottish Premiership relegation play-off against Dundee United, despite earning a last-day victory over 10-man Dundee.

Hamilton Academical's win over St Johnstone settled the play-off issue, but the Paisley side did their bit.

Sub Cody Cooke's second-half hat-trick won it at Dens Park and stretched their unbeaten run to six matches.

Cammy Kerr had given relegated Dundee the lead before Darren O'Dea saw red, with Scott Wright levelling at 2-2.

Oran Kearney's St Mirren meet Dundee United at Tannadice on Thursday, with the return in Paisley three days later.

St Mirren battle back after nervy start

The 2,500 St Mirren fans who made their way to Dens were in full voice from the off but Kearney's men looked nervous as the hosts seized control and took the lead in 14 minutes. Kenny Miller and Paul McGowan linked brilliantly to release captain Kerr, who slid in and hammered the ball high into the net.

However, with 20 minutes gone Dundee, as they have done so often this season, gave their opponents a lifeline. Defender O'Dea, playing his last game before taking up a coaching role at Motherwell, took a bad touch and after Brad Lyons nicked the ball the Irishman clipped him. It was a clear goalscoring opportunity and referee Alan Muir had no option but to reach for the red card.

The visitors offered little in the first half but Kearney threw on Cooke for defender Mateo Muzek at the break and he made the difference.

Eight minutes after the restart, it was all square when Cooke nodded in at the back post following great work by Paul McGinn. And the Englishman then grabbed his second within seven minutes, slotting home after a poor attempted clearance from keeper Jack Hamilton.

Danny Mullen then had an effort saved by Hamilton that looked easy to score before Dundee substitute Scott Wright collected a sublime cross-field pass from Ethan Robson and beat Vaclav Hladky to make it 2-2.

St Mirren refused to roll over though as Cooke completed his hat-trick and sealed the win with a shot that Hamilton should have done much better with.

Cody Cooke's back-post header got things started for St Mirren

Nerves of steel needed - analysis

St Mirren secured the win they needed but it was not enough and they now go into a battle with Dundee United, where they will require nerves of steel as well as a fair amount of courage and determination.

Credit has to go to Oran Kearney for making the switch at half-time, with Cooke staking a firm claim for a start in Thursday night's first leg at Tannadice. The St Mirren boss will, however, know they will need two top class performances to retain their place in the Premiership.

For the Dens Park men, this summer could prove to be one of big changes. A permanent manager will be appointed and many of the squad are likely to exit, but they will be expected to gel quickly to mount a promotion challenge.

Club chairman John Nelms says they have over 100 applicants for the job and that alone is an indication of the size of the club.