In a contest that ebbed and flowed at breakneck speed in the first half at Stadium 974, Xherdan Shaqiri put Switzerland ahead. Still, Serbia swiftly scored twice within 10 minutes through Aleksandar Mitrovic and Dusan Vlahovic to flip the game on its head.
Breel Embolo delivered another twist in an absorbing opening period by pulling the Switzerland side level just before the break, while Remo Freuler scored three minutes after the restart to restore their one-goal advantage again.
Switzerland had fired warning shots with barely 30 seconds on the clock, as the Serbian defence blocked captain Granit Xhaka's strike before goalkeeper Vanja Milinkovic-Savic denied both Embolo one-on-one and Xhaka on the rebound.
Serbia enjoyed a spell of pressure after that early scare, with Nikola Milenkovic heading wide from Dusan Tadic's corner before Andrija Zivkovic took aim from outside the penalty area and rattled the left post with a powerful effort.
Ricardo Rodriguez's cross in the 20th minute was cleared and fell to Djibril Sow, who picked out Shaqiri on the right. The midfielder fired home a strike that took a slight deflection off Strahinja Pavlovic on its way into the net.
Fulham frontman Mitrovic headed in Tadic's cross to deservedly draw Serbia level six minutes later. Tadic was involved again and slipped the ball through to Vlahovic, who steered a low shot past goalkeeper Gregor Kobel to complete the Serbian turnaround.
But Embolo slotted home Silvan Widmer's low cross in the 44th minute and Freuler kept the momentum going by thumping in the fifth goal of the evening, as two wonderfully worked moves from the Swiss attack proved to be Serbia's undoing.
Midway through the second half, Mitrovic went down too easily after a challenge from Fabian Schaer but his appeals for a penalty were turned down, and the Serbian dugout spilt onto the pitch protesting the referee's decision.
Switzerland finished with six points, level with Group G winners Brazil but behind on goal difference. Serbia, who needed a win to give themselves a fighting chance of advancing, finished bottom of the group with only one point. They have never moved past the World Cup group stage since the breakup of Yugoslavia.