Match ends, Livingston 1, Dundee 2.
Livingston 1-2 Dundee: Scott Wright inspires comeback victory
Scott Wright inspired Dundee as they came from behind to beat 10-man Livingston and move out of the Scottish Premiership's bottom two.
Shaun Byrne was dismissed for a challenge on Andreas Hadenius moments before Craig Halkett fired the hosts in front - Livi's first goal of 2019.
Andrew Nelson's flicked header from Wright's corner levelled matters.
And the forward's impressive free-kick ensured Dundee moved above Hamilton Academical on goal difference.
Jim McIntyre's side also stretched their advantage over bottom side St Mirren to five points.
Gary Holt's Livingston remain ninth and without a win since mid-December.
First-half profligacy doesn't cost Dundee
Dundee had several decent chances early on, with Nelson firing over from 20 yards before squandering a fantastic opportunity with a free header from six yards that flew over the bar.
There would be an even better opportunity for Wright as the ball arrived at his feet six yards from goal. It looked like being a certain goal but he shot high over the bar.
Livi hit the post through Ricki Lamie's cross and then lost Byrne on 14 minutes for a high boot on Andy Dales.
However, the hosts soon found themselves in front as Alan Lithgow's throw-in was flicked to the back post by Declan Gallagher and captain Halkett struck.
Dundee maintained the pressure but kept failing to hit the target, Dales squandering an opportunity just before half-time after being played clean through.
The away side would finally take their chance early in the second period. Wright crossed into the box and there was Nelson to loop a header into the net and score his fourth Dundee goal in six appearances.
Dundee then almost took the lead when Hadenius' replacement, Paul McGowan, was played through into the box but his shot whistled just wide.
Livingston's Ryan Hardie curled narrowly off target and Steven Lawless was booked for simulation following Jesse Curran's challenge in the Dundee box before Wright's moment of sublime brilliance - the Aberdeen loanee stepping up to bend a perfect free-kick into the top corner.
Visiting goalkeeper Seny Dieng pulled off a superb double save to deny first Halkett then Chris Erskine, and that proved enough to secure Dundee the points.
Massive win for Dundee - analysis
Dundee had only won once in their previous 12 games, so this victory was massive.
Not only was it deserved on balance of chances it would allow the Dark Blues to leapfrog Hamilton.
For Livingston that is now nine games without a win in all competitions, six of which have been defeats.
Livi 'denied stonewall penalty' - reaction
Livingston head coach Gary Holt: "We should have a stonewall penalty at a crucial point in the game for Jesse Curran's challenge on Steven Lawless. It's something that's cost us, it's cost the boys. It's cost them a chance to win the game. How you can book him for diving is beyond me.
"I didn't see Shaun Byrne's red card initially. I've had a look at it just from one angle so far. I think it's maybe a yellow but I'd need to see it from other angles."
Dundee manager Jim McIntyre: "I thought it was a stonewall red card for Shaun Byrne. I thought it was a really poor challenge at the time. It was quite high and reckless. I thought it was clumsy from Jesse Curran on Steven Lawless. I'd need to see it again.
"It was a goal fit to win any game from Scott Wright. We were delighted to come back. We lost a really poor goal. We showed a great reaction. Overall, I think we deserved to win the game."
- 14OdoffinSubstituted forLawsonat 57'minutes
- 6ByrneBooked at 14mins
- 7JacobsBooked at 83mins
- 9HardieSubstituted forLawlessat 74'minutesBooked at 77mins
- 17RobinsonSubstituted forErskineat 58'minutes
- 17DalesSubstituted forCurranat 75'minutes
- 28HadeniusSubstituted forMcGowanat 49'minutesBooked at 85mins
- 4WoodsBooked at 86mins
- 10WrightBooked at 84mins
- 21NelsonSubstituted forMillerat 58'minutes
- Greg Aitken
- Shots on Target
Second Half ends, Livingston 1, Dundee 2.
Foul by Declan Gallagher (Livingston).
Craig Curran (Dundee) wins a free kick on the left wing.
Corner, Dundee. Conceded by Declan Gallagher.
Steven Lawless (Livingston) wins a free kick in the attacking half.
Foul by Martin Woods (Dundee).
Corner, Livingston. Conceded by Seny Timothy Dieng.
Attempt saved. Craig Halkett (Livingston) right footed shot from outside the box is saved in the bottom left corner.
Declan Gallagher (Livingston) wins a free kick in the attacking half.
Foul by Craig Curran (Dundee).
Martin Woods (Dundee) is shown the yellow card for a bad foul.
Keaghan Jacobs (Livingston) wins a free kick in the defensive half.
Foul by Martin Woods (Dundee).
Paul McGowan (Dundee) is shown the yellow card for a bad foul.
Foul by Paul McGowan (Dundee).
Keaghan Jacobs (Livingston) wins a free kick in the attacking half.
Scott Wright (Dundee) is shown the yellow card for excessive celebration.
Goal! Livingston 1, Dundee 2. Scott Wright (Dundee) from a free kick with a right footed shot to the top right corner.
Keaghan Jacobs (Livingston) is shown the yellow card for a bad foul.
Foul by Keaghan Jacobs (Livingston).
Jesse Curran (Dundee) wins a free kick in the defensive half.
Corner, Dundee. Conceded by Alan Lithgow.
Corner, Dundee. Conceded by Scott Pittman.
Steven Lawless (Livingston) is shown the yellow card.
Corner, Livingston. Conceded by Ryan McGowan.
Attempt missed. Declan Gallagher (Livingston) right footed shot from outside the box is too high.
Substitution, Dundee. Jesse Curran replaces Andy Dales.
Substitution, Livingston. Steven Lawless replaces Ryan Hardie.
Ryan Hardie (Livingston) wins a free kick in the defensive half.
Foul by Genséric Kusunga (Dundee).
Attempt missed. Alan Lithgow (Livingston) header from the centre of the box misses to the left.
Corner, Livingston. Conceded by James Horsfield.
Attempt missed. Ryan Hardie (Livingston) right footed shot from the left side of the box is close, but misses to the right.
Andy Dales (Dundee) wins a free kick on the right wing.
Foul by Steve Tevi Lawson (Livingston).
Andy Dales (Dundee) wins a free kick in the defensive half.
Foul by Alan Lithgow (Livingston).
Attempt missed. Paul McGowan (Dundee) right footed shot from the right side of the box is close, but misses to the left.
Substitution, Livingston. Chris Erskine replaces Scott Robinson.