Norway's Alexander Kristoff won the European road race championships in a chaotic finish in Herning, with Elia Viviani coming second for Italy.