Braga and Bremen through after thrillers
Substitute Lima, 27, a Brazilian journeyman forward, came on to score a second-half hat-trick to give Braga a 4-3 win in Spain and send the Portuguese outfit 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 where the visitors let slip a two-goal lead in the last half hour.
It is the second time Partizan have qualified for the group stage. The first 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 for the first time with a 1-1 home draw against Salzburg clinching a 4-3 triumph overall.
It is the 10th season in a row Sheriff have failed to get through the qualifying stages while Salzburg, Austria's biggest-spending team, have fallen at the final hurdle four times in five seasons.
Braga snatched an away goal in the 32nd minute through Matheus, who also struck in the 1-0 first leg win.
Sevilla had squandered a flurry of early chances with Brazil striker Luis Fabiano and Mali's Frederic Kanoute the main culprits.
Lima, who played for a number of unfashionable Brazilian clubs before moving to Portugal last season to join Belenenses, doubled Braga's lead in the 58th minute by slotting home Matheus's pass.
Luis Fabiano and Jesus Navas hit back to make it 2-2 on the night, only for Lima to add two more goals in the last five minutes before Kanoute pulled one back for Sevilla in stoppage time.
Sampdoria, who grabbed an away goal in injury-time in Bremen last week, were quickly in the driving seat at home with Giampaolo Pazzini netting twice inside 13 minutes.
Substitute Antonio Cassano appeared to have sealed their win when he scored with a backheel five minutes from time but Rosenberg had other ideas as he struck with a low 20-metre shot with almost the last kick.
Peru striker Pizarro was then on target from 25 metres to shatter the Italians, who reached the 1992 European Cup final on their only previous appearance in the competition.
"It hurts because we were winning 3-0 and should have dealt with it better," Sampdoria captain Angelo Palombo told Sky television.
"It was a dream and would have meant lots of money to the club. I hope the squad stays together now."
Striker Cleo, another Brazilian who has made a bigger impact abroad than at home, scored twice in the first hour to put Partizan 2-0 ahead at Anderlecht, taking his tally in the tournament to eight after he was also on target last week.
Seventeen-year-old Romelu Lukaku pulled one back for the Belgians just after the hour and Guillaume Gillet levelled in the 71st minute with a dipping shot from outside the area.
However Partizan, the only Serbian team to have reached the group stage, weathered the storm and won on penalties.