They weren't that far off. Most were hovering around a tie with a margin of error of +/- 2-3%.
Trump won many of those states by 2-3%.
Trump won many of those states by 2-3%.
Otherwise the real result would be distributed around the mean within the margin of error.
There is some bias and the polls did not correctly factor that into their statistical model.