Norwegian Hanssen struck in the 90th minute to give the Dutch side a 2-1 home win over Levski Sofia and consign CSKA to a fourth place finish in the five-team group from which the top three qualify.
Heerenveen finished third behind group winners Olympique Marseille, who beat Dinamo Bucharest 2-1 at the Velodrome, and Levski. Dinamo finished bottom.
Red Star Belgrade's bid to go through failed after they were pegged back 2-2 at Racing Strasbourg by Kevin Gameiro's equaliser four minutes into injury time and they finished fourth in Group E.
Strasbourg won the group by one point from AS Roma, 3-1 home winners over Basel, and two above the Swiss side.
Red Star were on course to snatch third place after taking a 2-0 lead in France but Gameiro struck twice to dash their hopes, in the 79th and 94th minutes.
Bolton Wanderers scraped through in third place in Group H with a 1-1 draw at home against Sevilla, whose striker Adriano Correia equalised 15 minutes from time to cancel out Bruno N'Gotty's opener for the English side 10 minutes earlier.
Sevilla won the group on goal difference from Zenit St Petersburg and one point in front of Bolton.
After Thursday's final games in group A to D, the 24 qualifiers will be joined in the draw for the two-leg round of 32 with the eight teams that finished third in their respective Champions League groups last week.
Mario Gomez scored both goals in VfB Stuttgart's 2-1 home win over Rapid Bucharest in Group G which had already been settled before Wednesday night's matches. Rapid, Shakhtar Donetsk and Stuttgart finished in the top three places all on nine points.
More from rediff