It had seemed England, who had collapsed to 30 for four on Friday, might get through the third morning without losing a wicket.
But Marsh, called up after fellow medium-pace all-rounder Shane Watson was dropped after Australia's defeat in the first Test in Cardiff last week, succeeded where the frontline bowlers had failed by bowling Stokes off the inside edge for 87.
At lunch, England were 181 for five in reply to Australia's 566 for eight declared, a deficit of 385 runs and still needing a further 186 to make the Ashes-holders bat again.
Cook and Stokes checked Australia's progress with a fifth-wicket stand of 145 after coming together following a top-order collapse in the face of hostile fast bowling led by Mitchell Johnson.
Also Read
After Friday's play, which ended with England 85 for four, Johnson had tried to goad Stokes by questioning whether he would still continue to bat in the "aggressive" fashion that has been England's watchword under new Australian coach Trevor Bayliss.
But Stokes, who in May scored the fastest Test hundred ever seen at Lord's, off just 85 balls against New Zealand, showed good judgment after resuming on 38 not out.
Stokes then completed a 67-ball fifty when he off-drove Johnson for the eighth four of his innings, which also included a six.