Xhaka gave the hosts a 1-0 win when he ran on to Blerim Dzemaili's pass and fired a diagonal 25-metre shot on the turn into the far corner in the 74th minute.
Needing at least a point plus a favourable result in the other Group E match between Norway and second-placed Iceland, Slovenia created plenty of openings in an end-to-end second half as Switzerland also looked for the win despite having secured top spot.
Kevin Kampl, Slovenia's most creative player, had the best chance to put them ahead when he intercepted a pass, burst forward and saw his shot saved by Yann Sommer.
Slovenia, who played at the 2002 and 2010 World Cups, became increasingly open at the back as they pressed for a goal and, after surviving several near misses, were finally sunk by Xhaka's outstanding effort but with Iceland earning a 1-1 draw in Norway they would have needed to win to go through.
Switzerland, who qualified with a 2-1 win in Albania on Friday, finished with 24 points after their seventh win in 10 games. Slovenia finished third with 15 points, Iceland advancing to the playoffs with 17.