Graham Onions and Ben Stokes snatched Durham's first Championship win of the season after skittling Middlesex out for just 102 in their second innings.
After 35 wickets fell on the first two days of play, the visitors resumed with five wickets in hand, needing 60 runs.
But Onions and Chris Rushworth struck early to leave Middlesex on 71-7, and facing a dramatic run chase.
Stokes then attacked, removing Ollie Rayner (11) and Tim Murtagh (3) to secure the win with 15 runs to spare.
Middlesex had looked to be in control on day two, as Durham posted a second innings total of 200 to leave the visitors chasing just 118 runs to win.
But resuming day three on 58-5, Onions immediately piled on the pressure by taking the wicket of John Simpson (10), before Rushworth, who finished on 4-41, dismissed Gareth Berg (5).
With Middlesex nearing their target, and requiring just 22 runs with three wickets remaining, Onions (3-38) struck again, this time capturing Toby Roland-Jones (34).
That left Stokes - who had dislocated his finger the previous evening - to finish things off with two wickets in three overs to end on 2-8.
VIEWS FROM THE DRESSING ROOM
Durham captain Paul Collingwood told BBC Newcastle:
"It was another exceptional and amazing game. To have two games like this in two weeks is incredible. Last week we didn't get over the line but this week we did. It took all 11 of us to keep believing.
"Onions did a fantastic job keeping his end going and the other bowlers did their bit as well. There were some fantastic catches as well, particularly from the wicket-keeper who took an amazing one-handed legside catch early on to give us that spark.
"That wicket can look flat at times and then suddenly one pitches and doesn't get up above ankle height. So we knew with those conditions we would always have chances.
"The ball was swinging around and as tailenders it's always hard to combat that. We stuck to our game plan and it worked and we must keep believing in ourselves."
This page is best viewed in an up-to-date web browser with style sheets (CSS) enabled. While you will be able to view the content of this page in your current browser, you will not be able to get the full visual experience. Please consider upgrading your browser software or enabling style sheets (CSS) if you are able to do so.