The result delivered a major jolt to the Republican Party — Mr. Cantor had widely been considered the top candidate to succeed Speaker John A. Boehner — and it has the potential to change both the debate in Washington on immigration and, possibly, the midterm elections.