Surrey 380 and 152 for 5 (Burns 78) lead Somerset 398 (Gregory 129*, Hildreth 90) by 134 runs
Lewis Gregory's second County Championship century gave Somerset the upper hand on the third day of the match with Surrey at Taunton.
Gregory made an unbeaten 129 from 153 balls with 10 fours and five sixes as his side were bowled out for 398, from an overnight 243 for 5.
That gave Somerset a first-innings lead of 18 and Gregory was soon in the thick of the action again, claiming two wickets as Surrey, without the ill Dean Elgar, struggled to 152 for 5 at the close.
The hosts were also without a key player in seamer Jack Brooks, sidelined by a calf problem. First innings centurion Rory Burns again held Surrey together with 78 to guide them from a perilous 43 for 3 just before tea.
The day began with Somerset trailing by 137. Steve Davies had added only four to his overnight score of 54 when falling lbw to Gareth Batty, but Gregory, who started the morning on 18, moved confidently to his half-century off 69 balls.
Craig Overton contributed 15 to a seventh-wicket stand of 51 before Conor McKee had him caught behind off a glove.
The second new ball was taken at 303 for 7 and saw Gregory start to cut loose. Twice he effortlessly lifted deliveries from Ryan Patel over long-off for six and when Morne Morkel dropped short he was dispatched over the longest boundary at mid-wicket.
It was 353 for 7 at lunch, with Gregory on 96. The first ball of the afternoon session saw him dropped at cover off Morkel and he went to three figures off 121 balls.
Tim Groenewald helped add 64 and Jack Leach a further 32 in stands dominated by Gregory. But Somerset fell agonisingly short of a fifth batting point when last man Brooks, nursing his calf injury, had his middle stump uprooted by Rikki Clarke.
The slender advantage still looked useful as Surrey plunged to 19 for two, Mark Stoneman edging Gregory to Marcus Trescothick at second slip and Scott Borthwick falling lbw to Overton.
With Elgar unable to bat, Somerset pressed home their advantage. Leach bowled Patel between bat and pad with some flight and spin and at tea the visitors were 49 for 3. That became 94 for 4 when Gregory continued his memorable day by hurrying a ball through Ben Foakes' defence to trap him leg before for 9.
Skipper Burns was in defiant mood. Using his feet well to Leach, the left-hander brought up his second fifty of the game off 108 balls.
Will Jacks, on a pair, needed to be patient getting off the mark, but helped Burns add 54 before Leach produced another key breakthrough. Burns advanced down the track once too often and was stumped by Davies as the ball beat his outside edge. The celebrations of bowler and fielders confirmed it as potentially a match-winning moment.
Morkel was sent out as nightwatchman to join Jacks, who had shown good temperament in moving to 31, and the pair safely negotiated the last two overs of the day with their side leading by 134.