WASHINGTON — The surprise defeat of a conservative justice in a statewide Wisconsin election — despite a show of support from President Trump — drove Republicans and Democrats back to their 2020 electoral playbooks on Tuesday, as both parties examined whether a surge of enthusiasm and on-the-ground organization among Democrats could help them capture that critical battleground state in November.

Leaders of both parties said that the victory, by an overwhelming margin of more than 120,000 votes, could provide a road map for Democrats trying to beat Mr. Trump in November in Wisconsin (which he carried by 22,748 votes in 2016) and other states where he narrowly prevailed. Democrats did have an advantage, though: A presidential primary was on the ballot, which probably raised turnout.

Wisconsin was also the first major test of vote-by-mail efforts for the parties since the outbreak of the coronavirus. Democrats by all accounts had the superior program, forcing Republicans to reckon with what could be a challenge for Mr. Trump’s re-election efforts.

Mr. Trump and some Republicans have attacked vote-by-mail efforts in response to the virus, arguing without evidence that they enable fraud and favor Democrats. But the Wisconsin result was a clear sign for both parties that a strong mail-in strategy could be important in the general election.