Derbyshire gave their Division One survival hopes a boost as Shivnarine Chanderpaul brought home a two-wicket win over fellow strugglers Somerset.
The visitors reached their target of 244 after lunch had been taken with them just six runs short and eight wickets down at Taunton.
Chanderpaul finished unbeaten on 74, capitalising on a huge reprieve having been dropped at mid-on by Craig Meschede with 21 still needed.
Piyush Chawla claimed 5-97 and Jack Leach 3-54, but the two spinners couldn't quite finish off a Somerset fightback that made for a thrilling finale after they had conceded a first innings lead of 195.
Derbyshire began the fourth day on 127-4, needing a further 117 on a pitch offering plenty of turn for Chawla and Leach.
Somerset's hopes were raised when Chawla had Richard Johnson caught behind for a duck off a slow leg-break, but Alex Hughes then played positively to contribute 33 to a stand of 68 with Chanderpaul.
At 172-5 Somerset opted to change wicketkeepers, with Alex Barrow taking over behind the stumps so that Craig Kieswetter could bowl his occasional off-spinners.
It was a move that smacked of desperation and Kieswetter reclaimed the gloves after sending down three innocuous overs in which he was fortunate not to concede more than 14 runs.
Leach was the most threatening Somerset bowler and he built pressure with 20 successive dot balls from the River End before pinning Hughes lbw on the back-foot with the total on 195.
A see-saw contest swung again as Tom Poynton (7) was caught lbw trying to pull a Chawla long-hop and David Wainwright (7) was stumped advancing down the pitch to the Indian spinner.
That made it 216-8 and Chanderpaul survived a loud appeal for a catch at short-leg before Meschede spilled his chance, two-handed to his right, to let the experienced West Indian off the hook.
Lunch was delayed for 15 minutes but the players did leave the field at 12.45pm with the score 238-8. After lunch Somerset had their last throw of the dice - the second new ball - but it failed to reap reward and four leg-byes off Chanderpaul's hip settled the game.