Derbyshire boosted their hopes of claiming back-to-back victories in Division One of the LV= County Championship, reducing Middlesex to 25-2 after setting them 297.
Ollie Rayner followed up his first Championship half-century of the season with 5-67 to see Derbyshire bowled out for 160 in their second innings - only for the hosts to hit back before the end of day three.
Middlesex lost Joe Denly (two) and nightwatchman Steven Finn - who was out twice in the day without scoring - to leave them still needing a further 272 to beat the county currently bottom of the table.
The visitors had at least managed to avoid having to follow on in the morning session, Rayner driving Mark Footitt through the covers for the boundary needed to get them past their target of 236.
He finished up unbeaten on 52 as Footitt wrapped the innings up in the next over when Tim Murtagh was caught behind and Finn, who had replaced James Harris after his release by England, was leg before wicket second ball.
Derbyshire had a healthy first-innings lead of 136 but they were soon in trouble as Murtagh and Finn reduced them to 20-3 at lunch, reviving uncomfortable memories of Lord's in April when they were bowled out by the same opponents for just 60.
However, Shivnarine Chanderpaul (32) and Richard Johnson steadied the ship by adding 52 in 17 overs. The latter made a top score of 59 that included eight boundaries.
Rayner ended his knock and also had Tom Poynton and Footitt falling to catches in the deep to bring the innings to a conclusion, leaving Middlesex facing a tricky period before stumps as they began their run chase.
They lost Denly in the fourth over, lbw to a ball that kept low from Footitt, before Finn bagged a pair when he was leg before for the second time in the space of five-and-a-half hours.