Tim Murtagh took eight wickets on day two, as Middlesex moved into a potentially match-winning position after making Somerset follow-on in Taunton.
Murtagh also made a handy 29 at number 11 as the visitors reached 347 in their first innings, before he, Toby Roland-Jones and fit again James Harris tore into the Somerset top order.
The swing-bowler took 4/28 in the first innings, as Marcus Trescothick's men were bundled out for 152 on a usually placid Taunton surface.
And when Chris Rogers enforced the follow-on, Murtagh finished with remarkable figures of 4/22 as Somerset briefly faced the prospect of a defeat inside two days at 35/5.
Peter Trego's 58, in an unbeaten partnership of 77 with Jos Buttler (20), saved Somerset's blushes for now at least.
Young fast bowler Jamie Overton had earlier completed his first five-wicket haul, taking 6/95.
But his was a rare success story for Somerset on a day where Middlesex's championship challenge looked alive and well.