The Stoke City forward kept his cool to put the finishing touch on a brilliant second-half fightback from Vladimir Petkovic's side that began when Granit Xhaka scored a thunderous equaliser early in the second half.
Arsenal midfielder Xhaka defied Switzerland's reputation as a side lacking in attacking threat when he rattled the ball into the net from 25 yards, pulling his team back into a game that had threatened to get away from them.
Aleksandar Mitrovic wreaked havoc in Switzerland's box throughout the first half, scoring the second opportunity presented to him for a Serbia team that looked assured and confident after beating Costa Rica 1-0 in their first game.
But their early energy and poise faded and the defeat leaves Mladen Krstajic's team heading into their last Group E game against Brazil knowing only a win can guarantee them a spot in the knockout stages.
Meanwhile Switzerland will meet already-eliminated Costa Rica and the way they improved throughout the course of this game will give their Bosnian coach every confidence that they can secure the point they need against Costa Rica to be sure of a place in the knockout stages for the second consecutive World Cup.
Switzerland failed to deal with the threat of Mitrovic as the Newcastle United striker terrorised their defence from the outset, drawing a reaction save from Yann Sommer after five minutes and then finding the net shortly after.
Dusan Tadic burst down the right and checked back onto his left foot to whip in a cross that Mitrovic met with a well-aimed header into the left side of the net beyond Sommer's reach.
Blerim Dzemaili dragged a shot wide from inside the penalty area as Switzerland began to probe for a way back into the game, but Serbia pressed and harried them and Sergej Milinkovic-Savic fired narrowly wide with a rising 20-yard drive.
With almost half an hour played Steven Zuber found a hole in the Serbia defence and threaded a pass for Dzemaili who drew a good one-handed save from Vladimir Stojkovic down to the goalkeeper's right.
Switzerland were fortunate to go in only 1-0 down at half-time, though, after a corner found Dusko Tosic unmarked at the far post, only for the defender to scuff wide.
Having looked tentative in the final third all game, Switzerland were anything but after 52 minutes when Shaqiri's shot rebounded back to Xhaka and the midfielder let fly from 25 yards, bulging the far corner of the net with a curling drive.
Shaqiri hit the frame of the goal with a bending effort of his own before Mitrovic was denied an opportunity at the other end by some extremely close marking, the 23-year-old being wrestled to the ground by Fabian Schar and Stephan Lichtsteiner at the far post with no protection from the officials.
Switzerland substitute Mario Gavranovic was flagged offside as he hit the side-netting with what looked like a golden opportunity, but the break seemed to put the wind in the Swiss sails.
And, in the final minute of normal time, Gavranovic played a superb throughball to Shaqiri, who outpaced Tosic and nutmegged Stojkovic with a low finish that sent the Swiss fans wild and allowed his country to dream of the knockout phase.
Key Opta stats:
- Switzerland's 2-1 victory over Serbia is the first game at the 2018 World Cup to see a side win from a losing position.
- As an independent nation, Serbia have lost each of the six World Cup matches in which they have conceded.
- Switzerland have lost just one of their last 24 matches (W17 D6), a 2-0 defeat to Portugal in a World Cup qualifier in October 2017.
- Switzerland have conceded a goal in three consecutive World Cup games; they had only conceded in three of the previous 10 before this run.
- Stephan Lichtsteiner made his ninth World Cup appearance for Switzerland in this game – the most of any Swiss player in history.
- Aleksandar Mitrovic has scored 18 goals in 26 games for club and country in 2018.
- Five of Granit Xhaka's 10 goals for Switzerland have come from outside the box.
- Only Josef Hugi (6 goals) has scored more World Cup goals for Switzerland than Xherdan Shaqiri (four, tied with Robert Ballamann and Andre Abegglen).