A fiercely-contested encounter looked to be heading into extra-time until Lewis' howler on 88 minutes.
Jamie McGrath unleashed a shot from 22 yards straight at the experienced goalkeeper, who attempted to parry the ball down but it calamitously slipped between his own legs and he was unable to claw it off the line.
St Mirren deserved the victory after an excellent first-half performance where they grabbed an early lead courtesy of Ilkay Durmus' stunning free-kick on four minutes. After Dylan Connolly was fouled by Jonny Hayes, Durmus – making his return from injury – fired left-footed past Lewis into the bottom corner from 20 yards out.
The Buddies have struggled for goals this season but pushed forward relentlessly early on and almost doubled their advantage on eight minutes. Richard Tait was afforded the freedom to drive forward and the left-back crashed a low shot past Lewis but it struck the post and bounced to safety.
Despite Aberdeen's slight improvement, the hosts remained comfortable and had a strong shout for a penalty on 28 minutes. Tommie Hoban was manhandling Jonathan Obika as he attempted to reach a cross but referee Don Robertson wasn't interested and waved play on.
The impressive Connolly was a constant threat and he forced Lewis into a smart save after the Irishman displayed excellent skill to burst through defenders on 38 minutes. Minutes later, Obika somehow squandered an easy chance from four yards out, dragging the ball wide, and it proved to be costly.
Aberdeen had offered nothing as an attacking threat until they scored an equaliser on 42 minutes. The goal came in fortuitous fashion after Jonny Hayes' strike deflected into the path of Niall McGinn to poke past the advancing Jak Alnwick.
Derek McInnes made two changes at the interval and Aberdeen immediately went close when Ryan Hedges found Hoban unmarked from a corner but the 26 year-old headed wide when he should have scored.
Aberdeen appealed strongly for two penalties for handball around the 80th minute but those appeals were more in hope than expectation.
Substitute Junior Morias almost won it for the hosts in the 85th but Lewis made a smart stop low to his right before his late mistake.