Either team could have won, but two strikes from substitute Ross Caldwell, his first for the club, eased Tommy Craig's early season woes and sent the hosts into the third round.
The home side's start was ponderous to say the least as Isaac Osbourne, making his debut, traded passes with his central defenders on a warm, sunlit evening. But if Saints thought they could stroll through this tie, they were rudely disabused.
Referee Steven McLean awarded a free kick to Dunfemline midway into the St Mirren half. It was taken by Josh Falkingham and headed clear by Ellis Plummer, but only to Lewis Spence and the midfielder sent a well-judged shot just inside Marian Kello's right-hand post from just outside the box.
St Mirren continued to look subdued, while at the other end Plummer needed a timely tackle to thwart Chigozie Ugwu, and Michael Moffat sent a decent shot just wide. At last, midway through the half, the home side came close to recording their first competitive goal of the season. Gregg Wylde supplied a cross from the left which eventually fell to Adam Drury. He took a couple of touches across the box before firing in a shot which crashed back off the crossbar.
With yet another 45 minutes having elapsed without a St Mirren goal, both Osbourne and Steven Thompson were relieved of their duties at half-time. Within five minutes one of the replacements, Caldwell, showed how to do it with a darting run into the Dunfemline box before releasing a shot which took a deflection off central defender Gregor Buchanan and beat Ryan Scully.
The goal energised Saints, but also galvanised the visitors. After both sides had carved out decent openings, Callum Ball, the other half-time substitute, and Kenny McLean came closest to scoring with shots which forced Scully into decent saves.
With the game entering the final 20 minutes, the outstanding Falkingham nearly snatched the lead for his side with a first-time dink not just over Kello, but the bar.
Dunfemline were still giving as good as they got when Saints got their second. Again it was Caldwell to the rescue, this time with an assist from Ball, as the hosts progressed.