He had John Simpson lbw for a first-ball duck in his opening over before angling one across Scott Newman to have the left-hander caught low down at second slip.
Shakib then took over, the turn he got from the wearing surface proving just too much for the Middlesex batsmen.
Dawid Malan passed 1,000 first-class runs for the season, only to then move across his crease just before lunch to have his leg stump clipped as he missed an attempted flick off his pads.
And Dan Housego went just after the interval, lbw on the back foot.
Only first-innings centurion Owais Shah, with 25 in his final innings for the county, had seemed to have any idea of how to flourish against Shakib's left-arm spin.
But when he holed out to mid-on, it was the first of three wickets in one over for the former Bangladesh captain.
Gareth Berg was caught at slip two balls later, pushing forward, and the last ball of Shakib's sixth over saw Tim Murtagh slice a wildly optimistic drive to point, to leave Middlesex 54-7.
From there, the Middlesex lower order surrendered with barely a whimper.
Toby Roland-Jones was lbw to Shakib, going back to a well-flighted ball when he should have been forward, and Neil Dexter - the home side's last hope - was brilliantly caught for 21 by Vikram Solanki at backward short leg off Moeen Ali.
Fittingly, Shakib picked up the final wicket, when Steven Finn attempted a mow to leg, as Worcestershire maintained their record of not having lost a County Championship away match to Middlesex since 1985.
The day had begun with Worcestershire just 116 ahead and when Moeen went, rapidly followed by Jack Shantry for a duck, caught at the wicket off Pedro Collins, it seemed as if the match was going Middlesex's way.
But Andrew more than doubled his overnight 34 with some cleanly-struck blows, Richardson hanging around to help him add an important 34 for the last wicket.
Worcestershire director of cricket Steve Rhodes told BBC Hereford and Worcester: "The wicket turned far more than we thought it would do and obviously far more than they thought it would because they didn't play an out-and-out spinner in this game.
"I think that was a bit of a surprise but Shakib bowled really well in this game and he's bowled tightly for most of the summer and picked up wickets for us since he has been here.
"But this game he has turned the ball quite prodigiously down the hill and he has been a real handful."
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.