Whoever wins at Lord's will be crowned champions, while Somerset - who beat Nottinghamshire - will win their first title if the match is drawn or tied.
Tim Bresnan (142 not out) and Ryan Sidebottom guided Yorkshire to the four batting bonus points required to ensure a Yorkshire win would secure the title, regardless of Somerset's result.
Middlesex closed on 81-2, 39 behind.
The home side had been reduced to 2-2, but first-innings centurion Nick Gubbins and Dawid Malan remained unbeaten through to the close.
Earlier, the hosts missed opportunities to take control of the match in the morning session as Yorkshire's Azeem Rafiq was dropped twice on his way to 65.
Bresnan reached his hundred off 222 balls but he started to run out of partners, and last man Sidebottom was required to help the visitors past the pivotal figure of 350.
The pair came together at 334-9 and added 56 to forge a 120-run lead.
A rain shower took the players off with Yorkshire 349-9, and spinner Ollie Rayner bowled a brilliant maiden over after the hour-long break before Sidebottom struck a boundary off Toby Roland-Jones.
The home side's response to Yorkshire's 390 began dreadfully as Sam Robson edged to Alex Lees off Sidebottom for a second duck in the match.
Brooks then bowled Nick Compton for one, with Middlesex trailing by 118, before Gubbins and Malan led the recovery.
Yorkshire coach Jason Gillespie told BBC Radio Leeds: "Tim Bresnan did wonderfully well. It's one of the best knocks I've seen by a Yorkshire player during my time here. Take into account the situation and what was at stake - it was an incredibly disciplined knock.
"People questioned the decision to bat him at five, but the reality is he's been one of our most consistent batsmen of the summer. It allowed us to play a fifth seamer and we could attack because we knew we needed to take 20 wickets here to win the match.
"We know Somerset have won and we've got work to do, and both sides here at Lord's know they've got to win if they want to win the title. It's going to be a fascinating and massively entertaining final day."
Yorkshire's fighting third-day display against title rivals Middlesex kept alive their County Championship hopes.