Leicestershire overcame a late wobble to beat Gloucestershire by two wickets and condemn the losers to the wooden spoon.
Both sides were battling to avoid finishing bottom of the LV= County Championship Division Two but after being held up by Gloucester's last pair the Foxes secured the win they were looking for.
Resuming on 254-9, the visitors' last wicket pair of Jonathan Batty (40 not out)and Liam Norwell put on an important 42 runs with Norwell at the crease for an hour and 12 minutes.
Matthew Hoggard (3-30) finally ended the rearguard by bowling Norwell for seven and Leicestershire made stealthy headway from the outset as they set about chasing down 236.
The Foxes were coasting at 205-3 but then lost five wickets for 13 runs as Gloucestershire fought back.
But Wayne White held his nerve to hit the winning boundary off Will Gidman while Josh Cobb hit a blistering 65 off 51 balls and Ned Eckersley made 63.
It was Leicestershire's third win of the season and the 21 points lifted them to seventh in the table, with Gloucestershire replacing them at the foot of the table.
Claude Henderson picked up two wickets in the penultimate over of the day to give Leicestershire the upper hand in the battle to avoid the Division Two wooden spoon.
The veteran South African left-arm spinner dismissed Will Gidman and James Fuller as Gloucestershire closed on 254-9 in their second innings, leaving them with a lead of 193 going into the final day at Grace Road.
Wayne White also grabbed three wickets in one over as Gloucestershire had looked to set a challenging target. Dan Housego hit 62 and Will Gidman 72 off 81 balls, but Henderson's late double strike put Leicestershire in the driving seat.
Earlier, Fuller had taken three wickets for five runs in 10 balls to restrict the home side to a first-innings lead of 61.
Resuming at 220-5, Leicestershire had high hopes of building a sizeable first-innings lead in reply to their opponents' 234 all out, but they were dashed by Fuller's fiery spell.
Leicestershire teenager Shiv Thakor lit up a rain-hit second day of the Division Two encounter against Gloucestershire at Grace Road.
Thakor hit an unbeaten 68 off 96 balls to steer Leicestershire to 220-5 before the rain swept in and play was finally abandoned an hour and 40 minutes before the scheduled close.
With the start also delayed for 15 minutes because of a rain shower, only 38.2 overs were bowled in the day, during which Leicestershire added 126 runs for the loss of two wickets.
Resuming on 94-3 in reply to Gloucestershire's 234, the Foxes saw opener Greg Smith (77) bring up just his second half-century of the season before falling to Jack Taylor.
By then Josh Cobb had departed without adding to his overnight score of 10, leaving Leicestershire at 155-5.
From then on Thakor took centre stage, the 18-year-old hitting 11 boundaries as he bought up his fourth 50 in nine first-class innings.
Wayne White (20 not out) helped share in an unbroken stand of 65 before play was called off at 4.20pm by umpires Ismail Dawood and George Sharp.
Leicestershire and Gloucestershire are locked in a hard-fought battle after the opening day of their final LV= County Championship Division Two match at Grace Road.
The visitors were bowled out for 234 in 65.5 overs and the hosts then closed at 94-3 from 28 overs.
Gloucestershire stumbled to 71-4 after skipper Alex Gidman had won the toss and chosen to bat.
Ian Cockbain (48) and Hamish Marshall (47) then shared a fifth-wicket stand of 96 but the Foxes spin duo of Claude Henderson and Jigar Naik then took centre stage.
Henderson took 3-32 and Naik 2-36 as Gloucestershire lost their last four wickets for nine runs in four overs.
Leicestershire's reply began badly, with Michael Thornely out lbw to Will Gidman (2-24) without scoring.
But Greg Smith, recalled to the side after an unbeaten century in the Second XI Championship final last week, stood firm and was 47 not out at stumps despite losing Ned Eckersley (25) and Matt Boyce (10).