Judge says voters ‘fended off an unprecedented attack on our democracy’