Inverness Caledonian Thistle moved off the bottom of the Scottish Premier League after claiming three valuable points against St Mirren in Paisley.
Andrew Shinnie benefited from a blunder in the home defence to fire in an 11th-minute opener.
A first-half injury-time header from Steven Thompson levelled the scores at the break before a superb Jonny Hayes second-half strike claimed the points.
Thompson's late header almost sneaked a draw, keeper Ryan Esson saving well.
The win edges Terry Butcher's side up to ninth, two points above Aberdeen who now prop up the table. St Mirren slip to seventh.
Thompson returned to the starting line-up for the hosts, with full-back David van Zanten dropping out following last week's 5-0 defeat at Celtic Park.
Inverness made just two changes following their defeat by Hearts - one was enforced with Roman Golobart replacing the injured Josh Meekings, while Billy McKay was preferred to Gregory Tade up front.
With just under 10 minutes played, Thompson had a shot from close range that cleared the bar when he really should have found the net.
One minute later, the Inverness account was opened when Hayes stole possession and squared to Shinnie on the edge of the St Mirren penalty area to blast home.
McKay had the ball in the back of the St Mirren net five minutes later, but referee Euan Norris had already blown for offside.
St Mirren struggled to keep the ball out of their own half for most of the opening half-hour, although Chris Hogg had to be on his toes to keep out a dangerous Jeroen Tesselaar cross.
As the interval approached, Ross Tokely should have done better with a long-range effort from outside the St Mirren penalty area that sailed wide, then teammate Greg Tansey's right-footed shot from 18 yards inched past the near-side post.
On the stroke of half-time, McKay hit the St Mirren side-netting after running out of steam on the goal-line and Kenny McLean's long-range shot could not find a way through a throng of Inverness jerseys.
However, seconds before the half-time whistle Thompson rose unchallenged at the back post to meet a Gary Teale corner and head into the net.
Shortly after the re-start, St Mirren keeper Craig Sampson had to dive low to his right hand side to stop a McKay header, then Kenny Gillet had to be on full alert to clear a Paul McGowan cross at the other end.
Inverness keeper Esson kept out a right-footed Thompson shot from 18 yards out, then Teale powered in a long-range free-kick from the right-hand side of the pitch with Esson at full-stretch to tip the ball over the bar.
Inverness regained the lead when Hayes curled in a superb shot on the turn from 20 yards out.
Moments later, McKay could have increased the advantage further when he ended up in a goalmouth scrap and swung a foot at the ball from a prone position, but his effort inched wide of the mark.
The home fans' claims for a penalty in the final minutes were waved away when Gillet appeared to handle the ball inside the Inverness penalty area.
Two minutes of added on time were not enough for the hosts to scrape an equaliser, despite a close-range header from Thompson that Esson managed to hold on the line to secure three precious points.
This page is best viewed in an up-to-date web browser with style sheets (CSS) enabled. While you will be able to view the content of this page in your current browser, you will not be able to get the full visual experience. Please consider upgrading your browser software or enabling style sheets (CSS) if you are able to do so.