Sevilla, Sampdoria crash out
Unfashionable Braga denied Sevilla a place in the Champions League group stage by winning 4-3 in Spain thanks to a second-half hat-trick by Lima.
The Portuguese team completed a 5-3 aggregate victory in the play-off tie to reach the group stage for the first time and leave Spain with only three representatives in Europe's most prestigious club competition.
Braga also denied Sevilla a third group stage appearance in four seasons.
Matheus gave the visitors a 1-0 half-time lead before Lima opened his account just before the hour.
Swiss league champions Basel won 3-0 at Sheriff Tiraspol to complete a 4-0 aggregate victory over the Moldovans while Hapoel Tel Aviv qualified with a 1-1 draw at home to Salzburg who lost 4-3 on aggregate to fall at the playoff stage for the fourth time in five seasons.
Werder, leading 3-1 from the first leg, went 3-0 down at Sampdoria before substitute Markus Rosenberg scored in the 93rd minute to set up extra-time.
Claudio Pizarro then netted as the Bundesliga team lost 3-2 on the night but qualified 5-4 on aggregate to leave Spain and Italy with only three teams in Europe's top club competition.
There was further drama as Partizan Belgrade knocked out Anderlecht 3-2 on penalties after drawing 2-2 in Belgium after letting slip a two-goal lead in the last half hour.
It is the second time Partizan have qualified for the group stage. The first time was in 2003 when they defeated Newcastle United.