Neatly-taken second-half goals by Fakhreddine Ben Yousseff and Wahbi Khazri gave Tunisia a 2-1 victory over Panama in their final Group G match in Saransk on Thursday and secured the North Africans their first World Cup finals win in 40 years.
The result brought some vindication for Tunisia, who coach Nabil Maaloul had admitted before the game were demoralised after their defeats by England and Belgium.
But it was tough for Panama, making their first appearance in a World Cup finals, and for their fans in the Monrovia Arena who for a while could dream they might grab a historic win.
"We wanted to snatch this victory, and I wanted to score, and I did. This is a great day for Tunisia," said man of the match Ben Yousseff.
"We know it is the first time for the Panamanian side but it doesn't mean it was easy to defeat them."
The North Africans, playing fluent and composed football, had much the better of the first half.
But they trailed 1-0 at halftime against the run of play after a shot by Panama's Jose Luis Rodriguez took a deflection off Tunisian defender Yassine Meriah in the 33rd minute for an own goal.
Having failed to finish off several chances in the first half, Tunisia took six minutes to assert themselves after the restart. Ben Yousseff picked up a neat low cross from Khazri to slot the ball home from close range.
Ben Yousseff should have given Tunisia the lead minutes later but Panama goalkeeper Jaime Penedo stuck out his foot to parry the shot.
Khazri, who had always looked dangerous, obliged in the 66th minute, running unmarked on to a low cross from defender Oussama Haddadi to tap into an open goal.
Panama often seemed to lack confidence going forward, and they suffered when captain Roman Torres, who had marshalled the defence well, departed with an injury early in the second half.
Still, they pushed hard for an equaliser and caused anxious moments for Tunisia as the clock ticked away but lacked the killer instinct.
The two teams had already been eliminated from the tournament before the match started, both having lost to England and Belgium.
But they played for pride in a spirited duel and the fervour of the more than 37,000 fans in the Mordovia Arena belied the notion that this was a pointless match between to two lowly nations.
The North Africans, making their fifth appearance in the World Cup finals, had not won a game since beating Mexico in Argentina in 1978 to become the first African country to win a match at the tournament.
Panama were making their debut and will go home disappointed, having declared their dream of making history by taking at least a point.
Panama and Tunisia had both been at the wrong end of the biggest scoring games of the tournament, with Panama being thumped 6-1 by England and Tunisia going down 5-2 to Belgium.
Going into the game, Tunisia coach Maaloul had sounded frustrated but the victory cheered him up, at least a bit.
"Perhaps in the second match we should have been better. Our performance against England was very good...we should have been more defensive against Belgium," Maaloul said.
"When we landed in this group we knew our best hope will be to come third."
"This is an exceptional World Cup and we have four Arab teams. Perhaps the Arab squads have not reached the level. We have to improve the performance."