Thousands of "test" ballots were counted in unofficial results as if they were legitimate, sowing confusion for days about who made the cut in a contested race.