Virginia was a state Republicans thought they had rigged to win. Democrats not only won — they laid the groundwork for a fairer election system.

Democrats scored an enormous moral victory and a blow to Donald Trump on Tuesday by electing Ralph Northam as the next governor of Virginia.

But in addition to electing Northam, Democrats flipped 14 seats in the Virginia House of Delegates — the largest Democratic gain in a single election in the state since 1899. This victory triples the total number of Democratic state legislative pickups since Trump was elected, and reduces the GOP majority to just a few seats.

Many of these individual races were themselves inspiring. There was Danica Roem, the transgender journalist who beat a virulently antigay GOP lawmaker. There was Kathy Tran, who will be Virginia’s first Asian-American woman lawmaker. There was Chris Hurst, whose reporter girlfriend was shot and killed on live TV, and who gave up his career in news to go into politics and fight gun violence.

But Democrats did even more than win big on Tuesday. They broke a Republican gerrymandering scheme in Virginia that has been in force for nearly a decade.

For years, Republicans in Virginia have controlled the House of Delegates because they were allowed to draw their own district lines after the last census. GOP lawmakers played with district boundaries to pack Democratic voters into a few small districts, while spreading Republican voters out across several, thus rigging the races to skew more GOP than the popular vote.

Virginia is one of the most heavily such gerrymandered states, although Republicans have used this model to rig state legislatures nationwide. Some of these schemes were so blatantly illegal the Supreme Court struck them down, as in North Carolina.

Now that Virginia has a Democratic governor, and the GOP House caucus has been severely weakened, it will be almost impossible for Republicans to get a gerrymandered legislative map through when it is due to be redrawn in 2021. They will have to draw the map fairly.

Democrats’ stunning, inspirational victory in the House of Delegates is a signal that not only is Donald Trump on notice, the entire corrupt GOP machine is on notice with him. And with 2018 around the corner, Tuesday night is only the beginning.