Democratic Sen. Jon Tester has defeated Republican Matt Rosendale to win a third term representing Montana.