Surrey 360 and 57 for 5 (Bailey 4-34) need a further 151 to beat Lancashire 274 and 293 (Williams 61, Salt 54, Worrall 3-69)
Tom Bailey took four wickets in 16 balls in an 11-over opening spell of 4 for 34 to reduce Surrey to 57 for 5 in an extraordinary final hour at the Kia Oval and give Lancashire the chance of inflicting a first defeat of the season on the Division One leaders.
The county champions had earlier been frustrated by Will Williams, Bailey's new ball partner, who as nightwatcher batted four-and-a-quarter hours for a defiant career-best 61 to leave Surrey needing 208 to clinch a sixth victory in eight matches this season.
But by stumps on day three it was a Lancashire win that looked more likely as Bailey wrecked Surrey's top order after the home side had eventually bowled out Lancashire for 293 in their second innings, held up by Williams' stubborn resistance and also by a powerful 54 from Phil Salt, his second fifty of the game.
Bailey's magnificent opening burst brought him the wickets of Dom Sibley for 1 and Tom Latham next ball for a duck in his fifth over and then, in his sixth and seventh overs, the scalps of Jamie Smith for 4 and Ben Foakes for 5.
Sibley and Latham were both well held at second slip by substitute fielder Rob Jones, Smith was leg-before shouldering arms to an offcutter and Foakes caught behind, pushing out defensively.
And the drama continued when Surrey skipper Rory Burns fell for 20, caught at first slip from Jack Blatherwick's fourth ball, in the 20th of the 24 overs Lancashire bowled in a memorable mini-session. Will Jacks remains 19 not out.
Williams, a 30-year-old New Zealander with a UK passport, began the day on one not out in Lancashire's overnight 113 for 4, representing an overall lead of just 27, but he withstood Surrey's five-pronged pace attack - spearheaded by Dan Worrall's 3 for 69 - almost until tea to make his maiden first-class half-century.
Christchurch-born Williams' previous top score in 54 first-class matches was just 38, made for Canterbury against Wellington in February 2020. This was his 75th first-class innings, with his 698 previous runs coming at the lowly average of 13, but Williams, playing straight and defending competently, helped Salt to add 95 in 37 overs for the sixth wicket.
LV= Insurance County Championship title favourites Surrey resorted to a short-ball barrage against him after lunch, with the second new ball, and although Williams' run-scoring then slowed to a trickle - he made just ten in almost 30 overs in the afternoon session - he still resisted courageously and, in all, faced 220 balls.
Surrey had only enjoyed one success in a tense morning session, with Burns leaping high at mid-off to pull off a superb one-handed catch from Daryl Mitchell's lofted drive at Worrall.
New Zealand Test batter Mitchell, on 17 overnight, looked in good touch as he moved to 30 but in the 12th over of the day was left stunned by Burns' athleticism as he somehow clawed down a ball that seemed to be clearing him.
Then, on 150 for 5, with only five more runs added, Salt was dropped by Smith at extra cover off Tom Lawes, this time the fielder failing to hang on to a chance above his head.
Williams, on 23, edged Sam Curran at catchable height between slip and gully but otherwise batted with relative comfort against the Surrey seamers. And when Jacks was called up for a few overs before lunch, Williams drove the offspinner straight for six to bring up Lancashire's 200 and to take his own score to 49.
The 30-year-old's half-century arrived soon afterwards, from 124 balls, and Surrey's frustration grew when shortly after lunch Salt was put down off Curran on 30 by Latham, diving to his right at second slip, in the first over with the second new ball.
Another 32 runs were scored before Surrey could celebrate their sixth wicket of the innings, Salt being bowled behind his legs by Jordan Clark, the ball flicking his back pad on its way into leg stump as Lancashire's keeper-batter aimed towards square leg.
Balderson narrowly avoided being dismissed by his first ball, a vicious lifter which clipped an elbow on the way through to keeper Foakes, and the left-hander had made only 10 when he edged a drive at Sean Abbott to first slip.
Williams needed some on-field treatment after taking one nasty blow on the bicep on 57, ducking into an Abbott bouncer, and his brave resistance finally ended four overs before tea when he gloved a short ball from Lawes into Smith's hands at short leg.
Bailey's useful 25, including some robust off-side strokes, was cut short by a top-edged pull at Curran that was well-held on the deep square leg ropes by Worrall and Lancashire's dogged second-innings effort was finally over when No 11 Jack Morley fended a Worrall lifter to short leg.