Glamorgan spinner Dean Cosker took career-best match figures of 11 for 126 but Essex still hung on for a dramatic draw at Cardiff as last pair Chris Wright and Danesh Kaneria survived the final 13 balls.

James Foster had produced a stubborn half century which looked like helping Essex easily save the game. The wicketkeeper made 73 in nearly four hours from 228 balls, but from 164 for four they were reduced to 180 for nine in the space of 15.1 overs.

Essex had been left 320 to win from a minimum of 88 overs, but after being reduced to 38 for three on a turning wicket, Foster with the assistance of Mark Pettini and then Alastair Cook, steadied the ship until the final dramatic collapse.

For the draw Glamorgan took 10 points from the match to Essex's nine.

At the start of the final day Glamorgan added a further 17 runs to their overnight total of 279 for nine a lead of 302.

Jamie Dalrymple, 89 not out at the start of play, was stranded on 98 after last-man Garnett Kruger was caught behind off Graham Napier. Not only was Dalrymple two short of his fourth century of the summer but he was left one run shy of 1,000 first-class runs for the summer.

Essex were forced to open with John Maunders and Tom Westley as Cook was relegated down the order because he was off the field with food poisoning on the third day.

It was certainly Glamorgan's morning as they took three quick Essex wickets after the spinners Robert Croft and Dean Cosker opened the bowling.

Cosker broke through in only his third over bowling Westley, before Dalrymple struck with his fifth delivery to have Maunders caught at slip as Essex were reduced to 18 for two.

A third wicket soon followed when Mark Cosgrove took a fine one-handed catch diving to his right at leg slip to remove Matt Walker.

But then followed an impressive partnership from Foster and Pettini, lasting 31 overs before the latter was dismissed when he gave a bat and pad catch to Gareth Rees at short leg ending a 68-run alliance with Foster.

It was Adam Shanty who started the sudden collapse by having Cook caught at short leg. Foster went lbw to Croft, Napier was caught at silly point to give Cosker his 10th wicket, Tim Phillips was bowled by Croft and Cosker then broke through David Masters' defence.

Croft thought he had won the game from the penultimate ball when there was a claim of a catch at short leg off Wright, but the final pair survived to the end.