Leicester travelled to Naples knowing it would guarantee a top-two finish in Group C if it could avoid defeat, but first-half strikes from Adam Ounas and Elmas put the host ahead on Friday (AEDT).
Jonny Evans and Kiernan Dewsbury-Hall quickly restored parity in a chaotic opening 45 minutes, only for Elmas to net again after the break and decisively edge Napoli back in front.
Luciano Spalletti's side settled for second – with Spartak Moscow defeating Legia Warsaw, following a 98th-minute penalty save, to top the group – and go into a two-legged play-off in February, while the third-placed visitors face a tie at the same stage of the Europa Conference League.
In a frantic start, Mario Rui's goal-line clearance denied Timothy Castagne following Dewsbury-Hall's cutback, before Napoli went up the other end and Ounas finished into the bottom-left corner after just four minutes.
Napoli doubled its lead when Andrea Petagna unselfishly squared for Elmas to tap in, but Evans quickly responded by firing past Alex Meret after James Maddison's free-kick was deflected towards him.
And Leicester was soon level as Dewsbury-Hall expertly volleyed into the bottom-right corner from the edge of the area.
Kasper Schmeichel pushed away from Ounas after the break, but the Denmark international was powerless when Elmas steered in to restore Napoli's advantage.
Maddison then spurned a glorious chance as he cannoned onto the post following Giovanni Di Lorenzo's mistake, and Jamie Vardy headed over in stoppage time after Schmeichel's save from Kevin Malcuit had kept Leicester's hopes alive.