Chasing 213, the reigning champions sealed a four-wicket win with a straight six from Glenn Maxwell after 10 balls of the extra half-hour on day three had been used up.
The result moves Yorkshire into the top two behind new Division One leaders Durham, leaving them level on points with Middlesex who lost their top spot.
With plenty of time at their disposal, Yorkshire began their victory quest straight after lunch having bowled Middlesex out for 229 in their second innings, and Adam Lyth and Alex Lees carefully took 27 off the first 14 overs before the latter fell lbw to James Franklin.
Happily for Yorkshire, England batsman Gary Ballance found some of the touch that deserted him in the recent Tests, and with Lyth picking up boundaries whenever the opportunity arose the second-wicket stand moved on to 71 in 19 overs without too much trouble.
But the balance of power shifted again as Ballance was lured out of his crease by Ollie Rayner’s off-spin and in the next over from Toby Roland-Jones, Jonny Bairstow was first dropped by Franklin at first slip and then picked up at second by Rayner.
Captain Andrew Gale soothed nerves by getting off the mark by hitting Rayner for consecutive boundaries but the bowler kept Middlesex in the hunt by having Lyth caught behind for 67 from 131 deliveries with 11 sweetly-timed fours.
Jack Leaning showed positive intent by driving Rayner for four and six and stroking Roland-Jones to the cover boundary but, having moved to 25, he was caught at second slip off James Harris with 44 still needed for victory at 169 for five.
Gale’s calm momentarily deserted him as he stepped down the pitch to Tim Murtagh and edged into his stumps having made 37 with six fours.
Maxwell was joined by 20-year-old Will Rhodes and the game finally shifted Yorkshire’s way as the Australian at last found the right mix of attack and defence. With only 10 required when the extra half hour was claimed the result was a formality, Maxwell striking a four and six off the first four balls of Harris’ over to get Yorkshire over the finishing line.
Earlier, the game was nicely balanced when Middlesex resumed the third morning on 127 for four and leading by 110, but an astute piece of captaincy brought an immediate reward for Yorkshire.
Gale opted for the occasional off-spin of Lyth for the first over and after a couple of close lbw shouts his final ball was edged by Dawid Malan to Tim Bresnan at slip.
Franklin, 33 overnight, continued carefully to shape his best innings for some while but he lost John Simpson with the score on 159 when the wicketkeeper-batsman chopped Bresnan into his stumps.
With Steven Patterson more economical than ever, runs had to be chiselled out and only Rayner could keep Franklin company for any length of time. Rayner went softly in the end, however, gently driving Patterson to Ballance at short cover for 28.
It was Rhodes who finished off Middlesex in a rush as lunch approached.
In the space of 14 balls he had Harris lbw and Roland-Jones brilliantly caught at mid-wicket by Ballance before uprooting Murtagh’s off-stump, leaving Franklin stranded on 55 from 126 deliveries with five fours.
Yorkshire coach Jason Gillespie admitted it was far from easy but had faith his side would reach their victory target.
He said: “The game was a tough one but I was confident we could win it once we knew what we would be chasing and I would have been happy to chase 300. I would have backed our players to do that. It would have been tough but we have the players to get the job done.
“I was always quietly confident but Middlesex have a really good group of bowlers and the pitch was starting to turn for Ollie Rayner. The most pleasing thing is we maintained our positive intent throughout the game.”
On the slump to 131 for seven in the first innings, Gillespie said: “We have spoken about our top six having a job to do and you cannot go on having the lower order doing the job for you.
“It was pleasing, therefore, that Adam Lyth and Andrew Gale had time in the middle in the second innings and it was good to see Gary Ballance making a contribution. It was only 29 but in the context of the game it was very important.
“Our bowling was a lot better than in the last game at Taunton (against Somerset). Steve Patterson was fantastic with his accuracy and Jack Brooks’ five in the first innings showed he has the knack of taking wickets.”