A Tom Hateley free-kick snatched the three points for Motherwell in a thrilling match at Scottish Premier League basement team Inverness.
David Davis curled in an early opener for the hosts but Motherwell found themselves level at the interval when Shaun Hutchinson headed home.
'Well's Jamie Murphy and opponent Gregory Tade each hit the bar before Andrew Shinnie slotted Inverness ahead.
But Keith Lasley blasted Well level and Hateley hit a late winner.
Motherwell's match-winning goal had come about when Chris Hogg was sent off for bringing down Murphy on the edge of the box as he raced for goal.
Davis put Terry Butcher's team ahead after four minutes at the Caledonian Stadium, his side-footed first-time curling shot beating Darren Randolph in the Well goal.
That effort was followed by one from Greg Tansey, but the English midfielder's shot was directed straight at Randolph.
Sadly for the visitors, Steven Hammell was stretched off after a hefty challenge from Josh Meekings, with Ross Forbes taking his place. Meekings was booked.
Shinnie tested Randolph with a neat turn and shot at the edge of the box after a Tade lay-off.
And Tade set up Tansey moments later and his powerful shot was saved at full stretch by the Well keeper. Randolph.
But the game turned dramatically when Hutchinson rose to meet Hateley's cross and levelled the score with six minutes of the first half remaining.
Incredibly, Murphy could have snatched an ill-deserved half-time lead when his cross-come-shot hit the crossbar and the same player flashed a shot wide in stoppage time.
Early in the second half, Davis hammered a shot that was deflected for a corner, then Shane Sutherland blazed over the bar after good work by Tade.
The Frenchman rattled the Motherwell crossbar with a ferocious shot when a more delicate finish would have sufficed as Inverness looked the more likely team to take the three points.
Hutchinson made an important challenge on Shinnie to deny Inverness a goalscoring chance but the hosts, and Shinnie, could not be denied for long.
Jonny Hayes' introduction for Tade on 70 minutes had lifted the home fans and five minutes later he was instrumental in setting up Shinnie to coolly give Inverness a deserved lead.
Butcher will have been seething at how things transpired in the following moments.
His players backed off as experienced 'Well midfielder Lasley pushed forward and from wide on the right he smacked a screamer past Esson to level the score 90 seconds later.
And it worsened when Inverness defender Hogg was shown a straight red card in 83 minutes for hauling back Murphy on the edge of the box.
Hateley took responsibility for the set piece and fired a shot into the top left-hand corner of the goal to give the Steelmen a win that did not look likely.
Cruelly for the Highlanders, the result keeps them rooted to the bottom of the SPL table, while the visitors move three points clear of third-placed Celtic who drew 0-0 with Hibernian.
Davis was the first player on the scoresheet and could well have been the last, but he shot wide in the final move of the match.