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 went close after four minutes through Marvin Emnes before Accrington threatened after seven minutes when Michael Richardson’s shot cannoned back off goalkeeper Jayson Leutwiler..
Middlesbrough provided the perfect response, the opener coming after nine minutes when Jutkiewicz deftly chipped beyond goalkeeper Ian Dunbavin to slot into an open goal from six yards.
Accrington levelled after 38 minutes when Carver won the ball in the air and flicked a looping header over Leutwiler.
After the break Middlesbrough piled on the pressure and went close after 78 minutes as substitute Adam Reach’s shot was blocked.
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.
In stoppage time Grant Leadbitter forced Dunbavin to dive full length to fingertip the ball around the post, and secure the fine win.
Middlesbrough: Leutwiler, Hoyte, Friend, Leadbitter, Gibson, Rhys Williams, Carayol, Varga, Emnes (Luke Williams 78), Jutkiewicz (Reach 74), Ledesma (Main 74). Unused substitutes: Steele, Andrew Halliday, Whitehead, Smallwood.
Accrington Stanley: Dunbavin, Hunt, Atkinson, Richardson, Liddle, Aldred, Hatfield, Mingoia (Wilson 90), Clark (McCartan 73), Carver (Gray 73), Murphy. Unused substitutes: Joyce, Winnard, Miller, Windass.
Referee: S Duncan (Tyne & Wear).