Rangers need only a point in their final Champions League match against Lyon to progress to the knockout stages despite losing to Stuttgart.
Adam fired Rangers in front moments after coming on
Substitute Charlie Adam gave the visitors the lead with a cool finish from Carlos Cuellar's headed pass.
Cacau, who was a constant thorn in Rangers' side, equalised on the stroke of half-time with a clever back-heel.
Pavel Pardo put Stuttgart in front. Barry Ferguson equalised before Ciprian Marica volleyed home a late winner.
With Barcelona drawing 2-2 at Lyon, Rangers know a draw against the French side at Ibrox in December will see them progress.
Rangers manager Walter Smith gave Jean-Claude Darcheville the lone striker's role against Stuttgart, with Daniel Cousin dropping to the bench.
Kevin Thomson, who missed the 2-0 defeat by Barcelona in the Nou Camp through suspension, was recalled at the expense of Adam.
Stuttgart, who were looking for their first point in the group, were without striker Mario Gomez, who was missing with a rib injury.
Cacau equalised for Stuttgart on the stroke of half-time
DaMarcus Beasley had a great chance to put the visitors in front within 10 minutes, but his weak effort was easily saved by Schafer.
Cacau forced Rangers goalkeeper Allan McGregor into a superb save in the 19th minute after he broke free inside the box.
Darcheville then fired wide from the left-hand side of the penalty area when it looked easier to score.
The visitors took the lead after 27 minutes when they punished Stuttgart's poor defending.
Beasley's corner was flicked on by Cuellar and substitute Adam fired home from close range.
Stuttgart equalised on the stroke of half-time through Cacau's back-heel.
Rangers were forced into their second substitution after the break when Steven Naismith came on for the injured Beasley.
Pardo put the hosts in front with a 20-yard drive from the edge of the box, which McGregor got a hand to, but failed to keep out.
Rangers equalised with 20 minutes to go when Ferguson took advantage of calamitous defending.
Naismith intercepted Schafer's woeful pass and Ferguson profited with a calm finish from the centre of the penalty area.
The equaliser sparked the visitors into life and both sides pressed for a winner.
Marica put the hosts 3-2 up with a superb flick with his back to goal from Magnin's cross, which beat the despairing reach of McGregor.
VfB Stuttgart: Schafer, Beck, Fernando Meira, Delpierre, Magnin, Hilbert (Ewerthon 83), Pardo, Hitzlsperger, Khedira (Da Silva 46), Marica, Cacau (Tasci 87).
Subs Not Used: Langer, Osorio, Meissner, Farnerud.
Goals: Cacau 45, Pardo 62, Marica 85.
Rangers: McGregor, Hutton, Cuellar, Weir, Papac, Hemdani, Beasley (Naismith 49), Ferguson, Thomson, McCulloch (Adam 26), Darcheville (Cousin 82).
Subs Not Used: Carroll, Boyd, Broadfoot, Whittaker.
Booked: McCulloch, Adam, Hutton.
Goals: Adam 27, Ferguson 70.
Ref: Darko Ceferin (Slovenia).