Scotland qualified for their first World Cup since 1958 but, despite remaining unbeaten, were knocked out in the first round on goal difference.