Sevilla, who reached the last 16 of the Champions League last season, were handed a shock playoff defeat by unfashionable Braga on Tuesday while Werder Bremen pulled off a spectacular escape act to oust Sampdoria.
Lima, a 27-year-old Brazilian forward who has until now enjoyed a journeyman career, came on to score a second-half hat-trick to give Portuguese team Braga a 4-3 win in Spain and send them into the group stage for the first time 5-3 on aggregate.
Werder, leading 3-1 from the first leg, went 3-0 down at Sampdoria before substitute Markus Rosenberg scored in the third minute of stoppage time 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.
Swiss league champions Basel won 3-0 at Sheriff Tiraspol to complete a 4-0 aggregate win over the Moldovans while Hapoel Tel Aviv qualified with a 1-1 home draw against Salzburg, who lost 4-3 overall to fall at the playoff stage for the fourth time in five seasons.