Skipper Ben Brown equalled a Sussex wicketkeeping record with six second-innings catches as his side claimed a thrilling 28-run Specsavers County Championship win over Gloucestershire at Cheltenham.
The hosts were dismissed for 247, chasing a victory target of 276, with Jofra Archer taking four for 29 and Ollie Robinson four for 49.
James Bracey was last man out for 87 when a memorable contest was finally decided.
Gareth Roderick contributed 66 to a fifth-wicket stand of 138 with 21-year-old Bracey as Gloucestershire, at 176 for four, looked to be gaining the upper hand.
But in the end the pace bowling of Archer, who had match figures of eight for 91, and Robinson proved decisive in a match where the outcome was still in doubt at tea on the final day.
Sussex took 21 points to keep their promotion hopes alive, while the home side, who went into the game bottom of the Second Division, had to settle for six.
The day began with Gloucestershire 30 for two and a pair of nightwatchmen at the crease in Matt Taylor and George Drissell.
Both fell early to Robinson and Archer respectively and Sussex had their tails up with the hosts 38 for four, Brown having been involved in every dismissal.
A fascinating see-saw contest turned again when Bracey and Roderick settled in to bat with few alarms in bright sunshine, taking the score to 125 for four at lunch, with a further 151 required.
Left-hander Bracey was first to his half-century off 90 balls, with seven fours, and when Roderick followed him to fifty from 97 deliveries, with eight boundaries, Gloucestershire began to look favourites.
Roderick pulled a six off Davis Wiese as the stand reached 138 before fortunes swung again when he was bowled leg stump looking to sweep left-arm spinner Danny Briggs.
Gloucestershire needed exactly 100 at that point, and Sussex sensed their chance. With 21 added, Graeme van Buuren fell to a slip catch off Chris Jordan for 14 and when Ryan Higgins was caught down the leg-side by Brown off Archer the scoreboard read 215 for seven.
Bracey was looking unflappable and it seemed the hosts might reach tea without further loss. But Robinson had other ideas and Kieran Noema-Barnett became the fourth Gloucestershire player caught down the leg side, Brown taking his sixth catch.
With a new ball due soon after the interval and 34 runs still needed, Sussex looked marginally the more likely winners.
That became more certain when Craig Miles was pinned lbw by Robinson with only two added in the final session.
The new ball was taken at 246 for nine, with 30 needed, and it quickly accounted for Bracey, well caught diving forward at deep square by Briggs to give Robinson his fourth wicket and end the match.
Brown was quick to offer a consoling handshake to Bracey, who left the field with head bowed after enhancing his growing reputation.