Uber Technologies Inc. and Postmates Inc. sued California to challenge legislation that could force the companies to treat their drivers as employees, the latest escalation in a battle over the new law set to take effect in the New Year.

The companies, competitors in the food-delivery market, joined two drivers in the lawsuit filed in federal court Monday against the state and its attorney general, Xavier Becerra. The suit claims that the new law, known as Assembly Bill 5, or AB5, violates constitutional guarantees of equal...