With Juventus and Roma having secured automatic entry to the Champions League, Napoli required no less than a win at the San Paolo to leapfrog Lazio into third place and qualify for the competition's playoffs at the capital club's expense.
But after launching a second-half fightback thanks to a Gonzalo Higuain brace after early goals from Marco Parolo and Antonio Candreva had given Lazio a 2-0 half-time lead, the Argentinian blazed over a penalty minutes later - his fourth miss from the spot this season - to allow Lazio back into the game.
With the game delicately balanced at 2-2 and with both teams down to ten men, Lazio had done enough to hold on to third spot.
But the visitors pushed to make it sure, and with five minutes remaining Onazi put the match beyond Napoli's reach by firing across Mariano Andujar and inside the 'keeper's far post.
German veteran Klose added a fourth for Lazio in injury time to ensure a happy ending to a rollercoaster season for the Biancocelesti, who recently lost the Italian Cup final to Juventus and were stunned late against Roma last week to lose the city derby.
"We did a great job tonight to finish off a great season," Candreva told Sky Sport.
"Thankfully for us Higuain missed from the spot but we deserve this third-place finish and we welcome it, especially after the bitterness of losing the derby."
Napoli's defeat, as well as Fiorentina's 3-0 victory over Chievo, saw Rafael Benitez's men drop one place to fifth in what was the Spaniard's final game at the club ahead of his reported move to Real Madrid.
Napoli join Fiorentina in next season's Europa League, with Sampdoria, who finished seventh three points behind Genoa, set to claim the league's third spot in the competition after their city rivals were refused a European licence because their stadium does not meet UEFA standards.
Despite Fiorentina's solid finish, coach Vincenzo Montella has left doubts hanging over his future.
"We've had talks and there's a lot of agreement, but we'll take a few days to decide," Montella told Mediaset Premium.
"We'll see, although I have to say tonight I was given a little more reason to stay."
Icardi, Toni top scorers
Inter Milan saw Mauro Icardi hit a brace in another thrilling encounter, the Argentinian scoring twice after the break as the Nerazzurri snatched a 4-3 win over enterprising Empoli.
Icardi's two-goal haul allowed him to pull level with Serie A's leading scorer Luca Toni, who finished the season for Verona on 22 goals, but was not enough to secure a place in Europe for Roberto Mancini's men.
Inter finished eighth in Italy's top flight to join struggling city rivals AC Milan, who finished tenth, in missing out on Europe altogether next season.
Although he praised Icardi, Mancini said: "It was the right way to finish a season in which the results were not always positive.
"We have to start next season as we finished this one in the knowledge that we have to take Inter back to where they belong."
Champions Juventus finished the season with 26 wins and just three defeats from 38 games after being held 2-2 by Verona on Saturday in a match which saw Toni score once.
With their first double in 20 years already secure following a Cup final win over Lazio, Juventus will now set their sights on beating Barcelona in the final of the Champions League.
Juve coach Massimiliano Allegri hinted after a comparatively shaky performance by his side that his players' minds are already turned towards next week's showpiece in Berlin.
"We played well in parts, at other times we were less focused and made technical mistakes. We handled our lead badly, missing a penalty, and not seeing out the final few minutes," said Allegri.
"We'll rest Sunday and get to work on the game from Monday onwards. It's not every day you get to play a Champions League final and we need to prepare for it calmly."