Senegal reached the Africa Cup of Nations final for the second time as Tunisia defender Dylan Bronn's extra-time own goal gave them victory.
Both sides had penalties saved in normal time before Bronn inadvertently headed the only goal of the game.
Mouez Hassen tipped Sadio Mane's free-kick onto Bronn's head as Senegal - who face Algeria or Nigeria - moved a step closer to their first Afcon title.
Tunisia had a late penalty award overturned by VAR.
Senegal dominated the first half, producing seven shots to Tunisia's two, with Mane spurning their best opportunity when he missed an open goal.
Tunisia improved after the interval and were awarded a penalty when Ferjani Sassi's effort struck Kalidou Koulibaly's arm, but Sassi's spot-kick lacked power and direction and was saved by Alfred Gomis.
Four minutes later Senegal were given a penalty of their own when Ismaila Sarr was brought down by Bronn, but Henri Saivet's shot was kept out by Hassen.
The Tunisia goalkeeper then inadvertently gifted victory to Senegal, who will be without influential captain Koulibaly for the final as he is suspended.
Jim Goodwin endured a difficult start as St Mirren manager as his top-flight side lost to second-tier Dunfermline Athletic in their League Cup opener.
Stevie Crawford's team ran riot in the first half, with excellent goals from Ryan Dow, Andy Ryan and Tom Beadling.
Strikes from Cody Cooke and Danny Mullen in the space of two minutes threatened to spark a comeback, but St Mirren fell short.
Dunfermline move top of the group and are well-placed to reach the last 16.
St Mirren, meanwhile, will have to hope the Fifers slip up in their remaining three fixtures against League Two Albion Rovers and Edinburgh City, and Lowland League East Kilbride.
Alternatively, a strong second-placed finish could earn them a spot as one of the best four runners up.
Ruthless Dunfermline expose disjointed hosts
A turbulent pre-season for St Mirren involved changing manager for the 10th time in nine years and, as a result, a squad short of numbers for new boss Goodwin to work with. The former club captain said he had only had 12 training sessions so far, and it showed as his side were brutally cut open with ease by Championship opposition.
The problems started, but did not finish, in their left-hand channel. First, Dunfermline's loan signing Josh Coley picked up the ball after a neat one-two in midfield, drove forward and slipped in former Dundee United attacker Dow, who coolly rolled in the opener for a debut goal after signing from Peterhead.
Unable to learn their lesson, St Mirren were ruthlessly exposed once more five minutes later. Kevin Nisbet, last season's top scorer in League One, nicked the ball past the onrushing Stephen McGinn on halfway before finding Ryan. The 24-year-old had plenty to do and superbly cut inside on to his left foot, evaded Ethan Erhahon and Gary McKenzie, then curled a shot into the far corner.
The mauling subsided, but only fleetingly. Beadling pounced on a loose ball in midfield and set up Ryan once more, and when his effort came off a post Beadling smashed in the rebound to leave Goodwin watching on in disbelief.
But after the break, greater composure on the ball - and a stroke of fortune - hauled the hosts back into the match. Cooke's long-range effort hit Beadling and crept into the net, and barely two minutes later Mullen bundled the ball home after Dunfermline goalkeeper Ryan Scully fumbled an in-swinging corner.
Tony Andreu's fizzing shot was as close as St Mirren came to the equaliser though, despite plenty of pressure.
Goodwin's legendary status among the St Mirren faithful will no doubt buy him plenty of time to build. And on the evidence of the first 45 at least, patience will be required.
'They shouldn't be better than us' - reaction
St Mirren manager Jim Goodwin: "I've got to give the players credit for the little bit of character they showed in the second half. But if we had got that equaliser, it probably wouldn't have been justified.
"I thought Dunfermline were the better team on the day and that's the main concern for me. They're coming up here from the league below and they certainly shouldn't be the better team against us."
Dunfermline head coach Stevie Crawford: "It was testing towards the end of the game when you lose two goals back-to-back. But the players have shown the spirit they've shown all pre-season.
"I'm delighted that the boys have managed to grind it out and showed a bit of steel."