The Owls appeared to be cruising after Atdhe Nuhiu had struck either side of Stevie May’s first goal for the club.
Three-nil up after 57 minutes following Nuhiu’s second, Wednesday were in total control until Glenn Loovens brought down Boro fans’ favourite Kike.
Skipper Grant Leadbitter despatched the penalty, and then repeated the trick in the 92nd minute following Tom Lees’ handball, to set up a tense finish.
But Wednesday held on to take the spoils and lift themselves into the top six following a solid start to the campaign.
Boro started well as they passed with confidence, Kenneth Omeruo heading just over from a corner.
Yet they found themselves behind due to some dreadful set-piece defending at the other end.
After Tomas Mejias initially failed to deal with Jacques Maghoma’s delivery, the hosts made a hash of their attempted clearances – allowing Nuhiu to eventually find the net via a deflection.
Boro responded impressively as Adam Reach forced a fine fingertip save from the outstretched Keiren Westwood.
Undeterred, the home side pressed forward further, Leadbitter rattling the crossbar with a vicious free-kick.
The Owls were still looking menacing going forward, though, and nearly grabbed a second as Maghoma cut in from the left and fed May, whose side-footed effort was tipped on to the post by Mejias.
The game entered a lull thereafter, only for Wednesday to double their advantage through May.
Nuhiu flicked a hopeful, long free-kick into the path of the Scot, who looped a delightful lobbed volley over Mejias with the outside off his foot.
Buoyed by the freedom that second goal brought, Wednesday initially controlled proceedings through some neat play after the break.
And their ingenuity gleaned reward when Maghoma’s vicious delivery allowed Nuhiu to glance a header beyond Mejias.
Boro were not about to give up, however, with Kike forcing a smart save from Westwood after getting in behind.
And despite some home fans heading for the exit, Karanka’s men were given a lifeline when Loovens brought down Kike in the area.
Leadbitter converted the spot-kick, sending Westwood the wrong way, although Middlesbrough were lucky not to concede again when Giles Coke’s header hit the post.
The tension built as time wore on, Loovens almost heading beyond his own goalkeeper before Leadbitter’s effort struck the arm of Lees.
The midfielder made no mistake again from the spot, but his intervention prove too little, too late.