Glamorgan 286 and 293 for 9 (Wallace 75*, Rudolph 56, Bragg 54) lead Essex 319 (ten Doeschate 117, Foster 64, Wheater 59, Meschede 5-84) by 260 runs
Essex were brought down to earth after their overnight celebrations on securing promotion to Division One of the Specsavers County Championship as Glamorgan kept them in the field for much of another hot day at Chelmsford.
Mark Wallace, with a run-a-ball fifty, threatened to take the game away from the newly crowned Division Two champions in the early evening after Essex had snapped up five wickets for 33 in 13 overs either side of tea, including a spell of three for five in 18 balls.
With Glamorgan only 130 ahead with three wickets in hand, Essex's fourth victory on the trot looked a realistic prospect. However, by the close, Wallace's belligerence had brought him 75 and helped Glamorgan into a stronger position, 260 ahead with one wicket still to fall.
It was a particularly memorable day for two Glamorgan players: allrounder Craig Meschede took the first five-wicket haul of his career, and Will Bragg became the Welsh county's first batsman to 1000 Championship runs this summer.
Essex added 44 runs for the loss of four wickets in the first hour's play to give themselves a first-innings lead of 33, captain Ryan ten Doeschate taking his score on to 117 and James Foster shepherding the tail before being last out for 64, becoming Meschede's fifth wicket.
Glamorgan had rubbed out the arrears when on the point of lunch Nick Selman was trapped lbw to one from David Masters that kept low. That brought in Bragg to join Jacques Rudolph and together they put on 91 in 26 overs before ten Doeschate accounted for them both in the space of his first over.
Essex had gone into their penultimate Championship game with a side packed with batsmen, and were inconvenienced when Graham Napier limped off with a calf injury on the first afternoon. It meant a lot of overs to be shared between bit-part bowlers like the captain and Tom Westley.
Ten Doeschate brought himself on for the 39th over of the innings and had Rudolph chopping on to his first ball. With the final ball, and after the batsman had scampered the single that took him to 1000, Bragg tickled one down the leg side and was caught behind.
Jamie Porter accounted for Aneurin Donald shortly before tea with one that swung in and flicked the bails on its way through and straight after the interval, Kiran Carlson failed to repeat his maiden century from the first innings as he chased one down the leg side from Bopara and was caught behind for 1.
Glamorgan's post-tea collapse continued when Foster took another catch as Meschede edged Porter, and David Lloyd fell lbw to Bopara for 25. At that point three wickets had gone down in the space of 18 balls for the addition of five runs.
Mark Wallace and Owen Morgan repaired some of the damage to take Glamorgan past 200, the eighth-wicket pair putting on 54 in nine overs before Masters trapped Morgan with one that kept low. But Wallace carried on apace and reached his fifth fifty of the season from 49 balls, and Timm van der Gugten joined the party with a six over long-on in Dan Lawrence's first over before falling to the same bowler, a steepler held by Bopara at mid-off.
In the morning, Meschede took two of the four wickets to fall to finish with career-best figures of five for 84. But it was van der Gugten who ended ten Doeschate's 171-ball stay when he trapped him lbw in the fifth over of the day. Ten Doeschate's seventh-wicket stand with Foster - which saw them claim the batting point they needed for promotion on Tuesday afternoon - was worth 104 in 32 overs.
Napier came out to bat with Lawrence as his runner but could only slice Meschede to Lloyd at third man without scoring. Masters then chipped a delivery from Michael Hogan back to the bowler.
In between, Foster passed 50 in the Championship for the fourth time this season and hit Meschede on to the roof of a marquee at extra cover for the second six of his 126-ball knock. But Meschede took a measure of revenge by having him caught at wide mid-off by Rudolph off another attempted big hit for 64.