The outcome is the latest in a series of Democratic gains in downballot races, signaling possible shifts in voter sentiment.