PITTSBURGH — The special election deep in Trump country in southwest Pennsylvania on Tuesday has become an acid test for the allegiance of working-class voters, and organized labor has gone all in for the Democrat in the race, Conor Lamb.

Union activists have been knocking on members’ doors, standing at the gates of steel mills and generally trying to claw back votes from 2016, when Hillary Clinton failed to connect with blue-collar workers across the industrial Midwest.

If Mr. Lamb is able to score the stunning upset he is hoping for, he is clear about who should get the credit.

“You’ve been the heart and soul of this campaign,” he told a rally of union steelworkers at their Pittsburgh headquarters. He noted that a statue of their union’s first president stands in a Catholic church near his suburban home, because “that’s how we feel about our unions.”