The Sharks took 20 minutes to profit from their early dominance, and they scored a second try on the half hour mark through their lively halfback Charl McLeod.
The Blues' first attack of the match brought a try to the power wing Frank Halai.
The Blues lifted their game in the second half and scored again through Halai, who swatted off Lambie on the way to the tryline. Ranger then drew the Blues level, grabbing the ball from a ruck near the Sharks line soon after being sent on by coach John Kirwan in the 45th minute.
A Baden Kerr penalty edged the Blues in front, setting up the tense final minutes.
The Sharks hurled themselves at the Blues defence, with acting captain Bismarck du Plessis turning down a simple penalty shot in order to go for the winning try.
If Lambie was the villain for the Sharks, Blues first five-eighths Chris Noakes had an opening stanza to forget, having a kick charged down, putting a kickoff into touch, and then missing touch from a penalty.
The result left the Blues outside the top six and unlikely playoff participants with two rounds to play. They meet the sixth place Cheetahs in the next round before taking on the champion, in-form Chiefs.
The Cheetahs will get an automatic four points from their last round bye.
Sharks 22: (Marcell Coetzee, Charl McLeod, Riaan Viljoen tries; Patrick Lambie 2 con, pen)
Blues 20: (Frank Halai 2, Rene Ranger tries; Chris Noakes con, Baden Kerr pen).
Halftime: 17 - 5.