Rangers' qualification for the next round of the Champions League will go right down to the wire in their final group match against Lyon next month after they were beaten 3-2 by VFB Stuttgart in Germany.
Stuttgart started brightly by putting pressure on Rangers from the off and stretching visiting goalkeeper Allan McGregor.
He made an excellent save from Cacau and did well to punch the ball away when under pressure from the chasing Ciprian Marica.
Rangers were forced into an early change when Lee McCulloch injured himself after going in for a crunching tackle on Roberto Hilbert.
McCulloch was shown a yellow card for his trouble as he was helped from the pitch.
But, just as the Light Blues looked to reeling from the loss of one their most influential players, they were handed a lifeline with a corner against the run of play.
DaMarcus Beasley's set piece was headed down by Carlos Cuellar and Charlie Adam - newly arrived on the pitch as a replacement for McCulloch - swept the ball in from three yards out.
The goal spurred Stuttgart on to more attacking play and it was only the steadfast McGregor who kept them out for as long as he did.
Cacau, Thomas Hitzlsperger and youngster Sami Khedira all peppered the Rangers goal with long-range efforts which varied in accuracy.
But with first-half injury-time drawing to an end, Rangers' concentration slipped and the Germans levelled as Hitzlsperger knocked a short corner to Cacau who back-heeled it into the net.
The second half started as badly as the first half had ended for Rangers as Beasley was stretchered off the pitch with a knee injury following a collision with the Stuttgart keeper.
All the pressure came from the Germans and they got their reward on 62 minutes when Pavel Pardo produced a neat piece of play with Andreas Beck before blasting a shot just inside the upright from the edge of the area.
Midway through the half, substitute Steven Naismith dispossessed Mathieu Delpierre on the halfway line and when the ball reached Ferguson he slid it into the net from ten yards out.
But Stuttgart went ahead five minutes from time when Ludovic Magnin found Marica on the edge of the area and he flicked the ball high towards goal.
The ball took a deflection off Weir which gave McGregor no chance.
The result leaves Rangers level on points with Lyon - who drew 2-2 with Barcelona - going into the final round of matches.