Iceland had begun the match with the chance to leapfrog their rivals at the top of the group and could have led on 60 minutes but Birkir Bjarnason shot against the crossbar.
Defeat meant Iceland dropped to fourth in the group, with Norway's 3-1 win in Cyprus enough to move them up to second. Switzerland made the early running when Barnetta and Xherdan Shaqiri fizzed shots over the crossbar.
Iceland showed why they have enjoyed a good start to the campaign, however, and a Gylfi Sigurdsson free-kick forced Diego Benaglio to tip over.
Shaqiri worked home goalkeeper Hannes Thor Halldorsson into action but Benaglio had to make the best save of the half just before the break when he pushed Alfred Finnbogason's shot from 12 yards wide.
Iceland continued to threaten after the break and almost led when Bjarnason thumped his shot against the bar. It proved a decisive moment as Barnetta opened the scoring five minutes later with a curled finish into the top-right corner.
Gavranovic made the game safe for the Swiss 14 minutes from the end when he latched onto Stephan Lichtsteiner's pass from the right.