Liverpool's win at Udinese meant the Swiss side's efforts were in vain as they finished in third place in Group A, albeit level on 10 points with the Reds and Anzhi, who were already through. The defeat saw the Russians surrender top spot in the pool to Liverpool, though.
Young Boys went in front through Gonzalo Zarate in the 37th minute, although they conceded an equaliser just before the break to Odil Ahmedov.
But the hosts retook the lead six minutes into the second half, Moreno Costanzo on target, and after Anzhi had Lacina Traore sent off for two bookings 20 minutes from time, they sealed the win in the last minute through substitute Alexander Gonzalez.
Anzhi, with the pressure off, created the game's first chance as Oleg Shatov forced a smart parry from goalkeeper Marco Wolfli.
The Swiss side soon found their feet, though, and Zarate tested Vladimir Gabulov in the visitors' goal with a left-footed shot from the edge of the area and Raul Bobadilla had a close-range effort blocked.
Young Boys were having all of the play now with Costanzo working Gabulov from inside the area.
And they took a deserved lead in the 37th minute as Scott Sutter's header back across goal was poked home by Zarate.
Zarate also saw an effort come back off a post before the hosts were pegged back on the stroke of half-time.
Ahmedov fired a low shot into the net from Traore's pass to equalise with the last action of the half.
But the hosts were back in front in the 52nd minute with Costanzo pouncing on Mario Raimondi's knock-down and rifling a shot into the top corner from the centre of the area.
Young Boys kept up the pressure and Bobadilla crossed for Raphael Nuzzolo, whose shot was held by Gabulov.
The Russians suffered another setback when Traore was shown a second yellow card and, with their progression already assured, they showed little sign of getting another leveller.
Instead the hosts got a third in the last minute, as Michael Frey set up fellow replacement Gonzalez to score.
Events in Udine conspired against Young Boys, though, on an ultimately unsatisfactory night for the Swiss side and their opponents.