York City won the National League title in heartbreaking fashion, scoring a 99th-minute equaliser to beat Rochdale 1-1 and claim promotion.