The Nigerian fired the Magpies into the lead for the first time with 71 minutes gone seconds after replacing Michael Owen, and Lovenkrands sealed victory with four minutes remaining.
Boro took the lead through Habib Beye's third-minute own goal, but Steven Taylor levelled six minutes later after Mark Viduka had hit the post.
The first goal arrived after three minutes, but for Shearer, it came at the wrong end. Tuncay Sanli turned well on Alves' pass, but looked to have overrun the ball. He got there just ahead of the Harper, who blocked, only to see the rebound ricochet back off Beye and into his own net.
But if there was any sense of despondency at St James' it disappeared with nine minutes gone when Taylor rose to meet the first of a series of Danny Guthrie corners and guided a header past Brad Jones.
Viduka might have put the home side ahead with the cheekiest of efforts when he back-heeled Beye's 46th-minute cross wide of the far post, and Nicky Butt drilled a free-kick into the defensive wall as the Magpies started brightly once again.
But Boro's response was concerted and as the home side completely lost both their shape and concentration, it took an excellent save from Harper to keep out Gary O'Neil's goal-bound 57th-minute strike.
The Teessiders were by now looking the more likely to break the deadlock, and Shearer decided the time had come to replace Jonas Gutierrez with Lovenkrands. But it was Martins' arrival as a 70th-minute substitute for Owen which proved the turning point.
Viduka headed on a high ball past Kevin Nolan and the Nigerian stepped inside Matthew Bates before dispatching the ball past Jones despite slipping as he shot.
The noise inside St James' almost lifted the roof, although the game was far from over as the home fans settled down for an agonising finish. But Lovenkrands calmed the nerves with four minutes remaining when he thumped home Nolan's cross to seal a win as important as any in the club's recent history.