Finland looked to be heading for the knockout round after Natalia Kuikka scored from the penalty spot in the 79th minute, but the Swiss kept up the attack in the breathless dying minutes and Xhemaili scored with a tap-in in added time to blow the roof off at Stade de Geneve.
Switzerland, who needed only a draw to advance based on goal difference, finished second in Group A behind Norway after a game that for most of the night was far from a classic.
It is the first time the Swiss women have advanced to a knockout round in a European championship.
They will join Norway, who beat Iceland 4-3 to maintain their perfect record in the competition.
Winger Signe Gaupset made the most of her first start at the Women's Euros, scoring twice and creating two more goals for the Norwegains who had already secured victory in Group A with their third straight win.
Despite Gaupset's tremendous offensive performance, the Norwegians endured a nervy ending as Iceland scored two late goals, including a stoppage-time penalty after Marit Breatberg Lund was sent off for a clumsy challenge.
With Iceland playing for pride, having already been eliminated, Sveindis Jonsdottir netted their first goal at the tournament by reacting quickest when Alexandra Johannsdottir's header was spilled by Cecilie Fiskerstrand in the sixth minute.
Gaupset, one of six changes from the side that beat Finland 2-1 on Sunday, cancelled out Iceland's opening goal by firing a low volley from a corner in at the foot of the right-hand post in the 15th minute, and 11 minutes later she fired a left-footed drive into the opposite corner to make it 2-1.
Gaupset heaped more misery on Iceland by teeing up Frida Maanum for Norway's third goal four minutes after the break, and she set up Maanum for another in the 76th minute.
After dominating for much of the game, the wheels came off for Norway late on as Iceland battled bravely, scoring again through Hlin Eiriksdottir in the 84th minute.
Substitute Bratberg Lund was sent off in stoppage time for a foolish challenge that resulted in a penalty which Iceland captain Glodis Viggosdottir fired home to make it 4-3, but the Norwegians held on to finish top of the group with a perfect nine points.