Pete Buttigieg, a former mayor of South Bend, Indiana, narrowly defeated Senator Bernie Sanders in the Iowa caucuses with all precincts counted, the Iowa Democratic Party said on Thursday, after technical glitches hindered the counting of votes in the fist contest for the Democratic presidential nomination.