Owen Foster headed Alloa into a half-time lead in Airdrie, but Aidan Wilson and Euan Henderson’s penalty put the hosts in the driving seat.
Scott Taggart’s spot-kick tied the scores and would have sent both sides through to the last 16, but Steven Buchanan fired the visitors’ winner with a minute remaining.
Premiership side Dundee ended a disappointing group campaign with a 5-0 hammering of third-tier visitors Montrose.
A Simon Murray penalty – the captain’s first of the season – set Steven Pressley’s side on their way, the striker added his second after the break and late goals from Clark Robertson, Ryan Astley and Luke Graham completed the rout.
Watch all your favorite Amazon Prime Video Sports broadcasts live and free. Get access to NFL, NBA, NASCAR, WNBA, and more – all included with your Prime membership!