A Washington state judge upheld a Seattle ordinance allowing app-based ride-hailing drivers to vote to unionize, dealing a blow to Uber Technologies Inc.’s hopes of stalling the legislation.

Judge Beth Andrus of King County Superior Court issued the ruling on Friday that affirms the ordinance, which paves the way for the nation’s first unionization effort for app-based drivers.

The...