Essex and Northamptonshire shared 25 wickets on a bonkers first day on their LV=Insurance County Championship clash.
Northamptonshire were bowled out for 81 – with Cook grabbing five for 21 and his 50th scalp of the season – before Essex were restricted to 170 and an 89-run first-innings lead.
The visitors then lost five wickets against the new ball to end the day 23 for five, a deficit of 66, with Essex knowing a victory will hand them the Division Two trophy.
Having won the toss and batted, Ricardo Vasconcelos was the first of seven leg before victims – a joint record for Essex – as Porter pinned him in the third over.
Luke Procter saw his off stump cartwheeling backwards, Rob Keogh was lbw to Cook and Saif Zaib plumb in front to Shane Snater – the visitors 36 for four.
Gay showed skill in his innings – mixing five boundaries – although was slow to get his bat down to be lbw to Porter.
Josh Cobb, on his first red-ball appearance in two years, handed Cook his 50th scalp of the season when he was lbw before Tom Taylor was deemed to have edged behind three balls later.
Adam Rossington swept a six but was lbw next ball, Simon Kerrigan was lbw to give Cook his fifth and then Porter rounded off the innings by producing an edge off James Sales’ bat, which flew to Alastair Cook at first slip.
During the lunch interval, Essex bid farewell to club legend Ryan ten Doeschate and retired the No.27 shirt – the Holland international returning after 19 seasons at the county.
Despite it being high-quality bowling rather than gremlins in the pitch that cost Northamptonshire, Essex attacked in reply.
They had wiped out Northamptonshire’s total by the end of the 15th over, however had lost their first four wickets by the same point.
Nick Browne lasted until the sixth over when he edged to first slip, Essex having already scored 39, before Alastair Cook pushed to third slip.
Josh Rymell was bowled through the gate by Procter and Lawrence – who appeared fortunate to survive a strong LBW appeal on just four – was caught by Berg after a whirlwind innings of 33.
Michael Pepper and Simon Harmer both tamely edged to point, Paul Walter played over a straight ball to be bowled by Taylor, Snater and Sam Cook tickled behind and Wheater rounded off the innings when he was bowled for 34.
Jack White and Tom Taylor shared the wickets, claiming 4 for 40 and 4 for 67 respectively.
Essex won a first-innings lead and in 13 evening overs managed to make inroads. Vasconcelos will consider himself unfortunate after being adjudged LBW before Gay feathered Porter behind.
Keogh was caught Cook bowled Cook, nightwatchman Kerrigan nicked off and second nightwatchman Sales was castled to the last ball of a dramatic day.