Marseille late show snatches spot in last 16
The substitute's stunning 87th minute effort allowed Marseille to grab second place by one point from Olympiakos Piraeus, who beat Group F winners Arsenal 3-1 and for a time thought they were going through.
"This win will be engraved in the history of Marseille," coach Didier Deschamps told reporters.
"Football is marvellous when you win. We believed right until the end, both the players and the fans. There is also pride at reaching the last 16 for two straight years."
The French side, needing to win to qualify without depending on the Greek team's result, were apathetic for the first 45 minutes as they fell 2-0 down to a close-range goal from Jakub Blaszczykowski and a Mats Hummels penalty.
Loic Remy headed one back in first-half stoppage-time with their first real attack but Marseille still looked beaten until Ghanaian Andre Ayew headed the equaliser with five minutes to go.
That was still not enough to qualify until substitute Valbuena collected the ball near the touchline, jinked his way past three defenders and scored with a dipping right-foot drive from the edge of the penalty area.
"That goal before half-time gave us a boost and we knew we would then have chances. What we have done tonight is enormous," said Valbuena.
The French team finished second with 10 points with Olympiakos on nine and the Bundesliga champions embarrassingly last with four having had a small chance before kick-off of reaching the last 16.
Dortmund coach Jurgen Klopp, whose team are enjoying another good season domestically and are second in the Bundesliga, said: "To put it simply, it's bad. But we'll be back.
"We did everything right at the start, we weren't too hectic, 2-1 was unnecessary but not a great problem. But we undid it all in the second half."
The game had begun will all sorts of possible permutations for the group.
Dortmund's most realistic hope was to win by three goals and hope Olympiakos lost to already-qualified Arsenal.
There was also a possibility that all three teams could finish with seven points if Borussia won and the Greeks drew, a scenario which would have had calculators working overtime.
Dortmund went ahead in the 23rd minute following a long throw-in on the right which was brought under control by Robert Lewandowski before his fellow Pole Blaszczykowski fired in from close range.
They increased their lead in the 32nd minute when Sebastian Kehl was fouled and Hummels converted the penalty.
Kehl was carried off on a stretcher after a kick in the face but Dortmund said nothing was broken. The four-minute delay as he was taken off caused the match to finish later than the Olympiakos game.
The French side, very inconsistent in Ligue 1, pulled one back deep into first-half stoppage-time with their first real attack, Remy stealing in front of his marker to meet Morgan Amalfitano's cross with a diving header.
Ayew headed the equaliser in the 85th minute and Dortmund were still recovering for that when Valbuena superbly hit the decisive goal which sent the away fans into raptures.
Before the late burst Olympiakos thought they were going through but the Greeks must now settle for the Europa League.
French champions Lille have to beat Trabzonspor on Wednesday to join Marseille in the last 16 draw with fellow French side Olympique Lyon having little chance of progressing.