Szabolcs Huszti kept his nerve to fire home a late penalty and secure a 3-2 victory and Hannover's qualification for the UEFA Europa League knockout stages at the expense of nine-man Helsingborg.
Huszti scored an 88th-minute spot-kick whose award for a foul on Artur Sobiech so enraged the visitors they had both Peter Larsson and Walid Atta sent off for protesting.
And the goal proved enough for the Germans to guarantee their progression after group rivals Twente and Levante played out a goalless draw in Holland.
Hannover looked set to coast to victory after two Mame Biram Diouf goals gave them a comfortable 2-0 lead.
Diouf opened the scoring after three minutes when he converted a cross from Huszti, and threatened to increase his lead when he headed straight at visiting keeper Par Hansson in the 11th minute.
He came close again seven minutes later and Didier Konan fired over, but the Swedes briefly rallied at the start of the second half with Atta narrowly missing with a close-range header.
Diouf made it 2-0 after 50 minutes when he headed home a Lars Stindl cross, but Helsingborg hit back nine minutes later when Nikola Djurdjic got on the end of a cross by Mattias Lindstrom to give them hope.
The Swedes snatched their equaliser in the 66th minute when Christoffer Andersson's free-kick was only half-cleared and Alejandro Bedoya found the net from 12 yards.
Both sides had chances to win it before the late drama that started when Lindstrom was ruled to have fouled Sobiech in the box, sparking a furious response from the visitors.