Somerset teenager Jamie Overton finished with career-best figures of 4-65 in 21 overs on the opening day at Taunton, as Middlesex reached 293-8 by the close.
Left-arm spinner Jack Leach returned 3-36, but half-centuries from Chris Rogers (57), Joe Denly (55) and Neil Dexter, who was unbeaten on 73 at the close, kept the visitors well in the game.
Rogers and Sam Robson took the score to 76 in the 24th over before Robson, who had looked the more solid of the pair, edged Overton to Marcus Trescothick at second slip for 42.
Rogers and Denly pushed on to 158 before Somerset hit back with three wickets for just four runs, started when Rogers nicked Overton to wicketkeeper Jos Buttler.
The next over saw left-arm spinner Leach bowl Denly shouldering arms and the one after that brought the demise of Dawid Malan, for two, snapped up by Trescothick in the slips off Overton.
Dexter and John Simpson steadied the ship before Simpson, on 22, gave a sharp catch to James Hildreth at short-leg off Leach to make it 211-5.
Gareth Berg swept a catch to Peter Trego at mid-wicket to give 21-year-old Leach his third wicket and Middlesex had slumped to 222-7 when James Harris was caught behind off Lewis Gregory.
Dexter moved to a valuable fifty off 110 balls, with six fours, before Toby Roland-Jones, who had helped add 48 for the eighth wicket edged Overton to Hildreth at first slip and fell for 21.
Tom Smith then joined Dexter in the quest for a third batting bonus point, which will require seven more runs in the morning.
By stumps Dexter had faced 139 balls and extended his boundary count to eight.