In a game of two halves in the South of France, Chancel Mbemba's opener in first-half stoppage time was cancelled out by Clement Lenglet nine minutes after the interval, but Pierre-Emile Hojbjerg netted a 95th-minute winner with the last kick of the game to help Spurs snatch all three points.
Antonio Conte's side, who required just a point to progress to the knockout rounds, followed up a dreadful first-half showing with a much-improved display after the break, which helped them to get over the line and remain at the summit of Group D.
Eintracht Frankfurt will join Spurs in the last 16 after they also came from behind to win 2-1 away against Sporting Lisbon, who finish third in the group and will drop down into the Europa League.
As for Marseille, they started the night bottom of Group D and they remain at the foot of the group, with a draw seeing them crash out of Europe altogether.
Marseille made a bright start to the contest in front of a raucous Stade Velodrome crowd and they dominated the first half with 70% possession, while Tottenham - who wee without the presence of Conte on the touchline following his red card last week - where chasing shadows and struggled to escape their own half.
Spurs' were dealt a major injury blow in the 23rd minute as Son Heung-min required treatment for several minutes after his jaw collided with the shoulder of Mbemba during an aerial challenge. The South Korean star gingerly walked down the tunnel and the North Londoners switch to a 3-5-2 formation following the introduction of Yves Bissouma off the substitutes' bench.
Shortly before Son's withdrawal, Tottenham were given an early reminder of Alexis Sanchez's quality in the final third; the former Arsenal forward sharply turned inside the area and fired a shot at goal, but Hugo Lloris was equal to it at the near post.
Lloris was called into action again just after the half-hour mark, with the Frenchman at full stretch to brilliantly tip a venomous left-footed strike from Jordan Veretout away from danger.
With Marseille pilling on the pressure, half time could not have come soon enough for Spurs, but the fourth official indicated seven additional minutes following Son's lengthy treatment and Marseille eventually made the breakthrough courtesy of a towering head from Mbemba.
Tottenham thought Marseille were wrongly awarded a corner, but that was not the case and the Spurs' backline switched off, allowing the hosts to take a short corner, with Veretout curling a perfect cross towards former Newcastle United man Mbemba to head home unmarked at the far post.
Harry Kane eventually fired Tottenham's first and only shot on goal in the first half moments before the half-time whistle blew, with the striker's powerful effort from the edge of the area tipped over the crossbar by former Spurs loanee Pau Lopez.
Spurs supporters will have been disappointed with their side's first-half performance, but they came out looking a completely different outfit in the second 45, and they were back on level terms in the 54th minute.
A beautifully flighted free-kick delivery from Ivan Perisic picked out Lengelt, who directed his towering header from inside the penalty area into the bottom-right corner.
Lenglet's equaliser kicked Tottenham into gear and gave them belief to search for a winner, and they almost took the lead 10 minutes from time when Lucas Moura teed up Hojbjerg inside the area, but the Danish midfielder could only watch his side-footed effort smack the face of the crossbar.
Perisic then made a crucial block at the other end just moments later to prevent a close-range strike from Sanchez hitting the target.
Another former Arsenal man in Sead Kolasinac missed a glorious chance to win the match in the 87th minute as he somehow failed to hit the target with a header from just a few yards out following a delightful cross towards the far post from Sanchez.
That missed chance proved costly, and as Marseille pushed for the winner they required to advance to the last 16, the French outfit were caught on the counter-attack in the fifth minute of second-half stoppage time, with Kane setting up Hojbjerg to find the back of the net and silence the heartbroken home supporters.
Tottenham and Group D runners-up Frankfurt will discover their opponents in the Champions League last 16 when the draw is made next Monday.