Tim Southee claimed three late wickets as New Zealand reduced England to 180 for six on a dramatic third day of the first Test at Lord's on Saturday.
A patient third-wicket partnership of 123 between Joe Root and Jonathan Trott looked to have put England in control of the match but the touring side grabbed four wickets for 12 runs in the final session to give themselves a scent of victory.
England, who bowled New Zealand out for 207 in their first innings, lead by 205 runs with two days remaining.
Cook, on 21, was well caught by Dean Brownlie diving at third slip off Trent Boult and Compton was comprehensively bowled for 15 by a fine delivery from left-armer Neil Wagner.
Trott and Root dug in, however, mixing watchful defence with determination to dispatch loose balls.
Root cut Wagner to the cover boundary to reach his second Test fifty which came off 78 balls and included six fours.
Trott, leaving anything wide of the stumps, looked untroubled by the bowlers and the pair's only problem was some erratic running between the wickets which twice nearly cost Root his wicket.
Trott sent back Root who was looking for a quick single and New Zealand wicketkeeper BJ Watling suffered a knee injury as he tried to get the ball on to the stumps, forcing him to leave the field two overs later.
New Zealand captain Brendon McCullum took over the wicketkeeper's gloves but caused a stir at the home of cricket when he emerged from the pavilion without any pads on.
As Lord's bathed in warm sunshine for the first time in the match, Root and Trott picked off runs with ease and New Zealand's problems increased when spinner Bruce Martin was also forced off the field.
Root looked on course to score his first Test century but, on 71, Southee ripped a full-length delivery through the right-hander's defences to take out his middle stump.
Trott reached his fifty off 128 balls with a streaky edge through the slips off Kane Williamson.
Jonny Bairstow was bowled by another full-length delivery from Southee for five and Matt Prior, out first ball in the first innings, bagged a pair when he tamely pulled a shot ball from Southee to substitute fielder Martin Guptill at square leg.
Trott was bowled by part-time off-spinner Williamson for 56 and Ian Bell, who spent most of the day back at his hotel suffering from flu, and nightwatchman Steven Finn survived the final overs surrounded by close fieldsmen.
England's pace attack sliced through the New Zealand tail in the morning.
James Anderson, fresh from taking his 300th Test wicket on Friday, completed figures of five for 47 and Finn took four for 63 as England secured a first-innings lead of 25 runs.
After New Zealand had resumed on 153 for four, Stuart Broad struck in his first over of the day, McCullum driving loosely at a full-length delivery and nicking the ball to wicketkeeper Prior.
The obdurate Williamson reached his fifty off 158 balls but his four-hour innings ended on 60 when he glanced a leg-side ball from Anderson through to Prior.
Southee skied Finn into the covers where Root took a simple catch and Anderson picked up his fifth wicket by bowling Bruce Martin for a duck with a perfect seaming delivery which clipped the top of off stump.
Finn wrapped up the tail, Watling edging a short ball through to Prior for 17 and Trent Boult prodding a simple catch to Anderson at gully.
Photograph: Gareth Copley/Getty Images
Taylor leads New Zealand revival after Anderson milestone
NZ keen to complete 'unfinished business' in England
Auckland Test: Boult puts New Zealand in control v England
Cook's exit leaves England battling to save Test
Long way to go, says Anderson after 300th Test wicket