The former winners of the competition went ahead early on through Lukas Jutkiewicz and had a flurry of chances to seal it but were caught cold just before the break by Marcus Carver, then the League Two minnows weathered heavy second-half pressure before snatching victory through Piero Mingoia.
Middlesbrough started brightly and went close after four minutes when Grant Leadbitter squared for Marvin Emnes in space 10 yards out, but he could only fire against the legs of Ian Dunbavin. From the corner that followed, Jutkiewicz sent a glancing header flashing wide.
Accrington threatened after seven minutes when a cross found Michael Richardson in the box and he cracked in a low effort that cannoned back off goalkeeper Jayson Leutwiler. From the rebound, Michael Liddle blazed over.
If Middlesbrough were rattled, they provided the perfect response. The opener came after nine minutes when a half-cleared corner was headed back into the danger area by Jozsef Varga for Jutkiewicz to deftly chip beyond Dunbavin and then slot into an open goal from six yards.
Jutkiewicz could have had a second goal after 15 minutes when Justin Hoyte crossed towards the striker, but defender Tom Aldred came sliding in superbly to ward off the danger.
Middlesbrough continued to press and first Mustapha Carayol and then Emmanuel Ledesma put efforts wide.
Accrington levelled after 38 minutes when Carver won the ball in the air and flicked a looping header over Leutwiler. Rhys Williams attempted to hook the ball clear but the linesman immediately flagged to indicate the ball had crossed the line.
The hosts almost regained the lead just before the break as Carayol wriggled into the box but his first effort was charged down by Carver and his second was deflected wide.
After the break Middlesbrough piled on the pressure and in the early stages a thumping shot from Jutkiewicz was headed clear before the same player spurned a great chance from a swift break.
Leadbitter unloaded a fierce 18-yard low shot that defender Will Hatfield stretched to divert over the bar.
Middlesbrough went close after 78 minutes as substitute Adam Reach’s shot was blocked and fellow substitute Luke Williams scooped the rebound over from eight yards.
Then the home side and their supporters were stunned in the 82nd minute as Accrington scored, Mingoia ramming home through a crowd of players after Boro failed to adequately clear a corner.
There followed an inevitable late assault on the Accrington goal that saw Reach stab just wide and Varga send a low shot also narrowly off target. In stoppage time Leadbitter forced Dunbavin to dive full length to fingertip the ball around the post, and secure the fine win.