Three dozen union workers gathered outside city hall here on Thursday to rally against the global free-trade deals they believe have harmed Americans like them. Their candidate was Katie McGinty, the Democrats’ nominee for Senate in Pennsylvania. But their spiritual leader was Republican Donald Trump.

“He recognized there’s some problems we need to solve,” said McGinty, who is challenging Sen. Patrick J. Toomey (R), a free-trade advocate. “One, we have to stop bad trade agreements. . . . And two, we have to take the Chinese on when they manipulate their currency and dump goods in our markets.”

Just two days earlier, Trump had delivered a blistering speech at an aluminum recycling plant near Pittsburgh in which he called U.S. trade policies a ­“politician-made disaster” that has betrayed the working class. McGinty, surrounded by electricians, pipe fitters and steelworkers, declared that while Trump usually spouts “nonsense,” he had, in this case, “recognized a couple of truths.”

Of the many ways Trump, the GOP’s presumptive presidential nominee, has scrambled the 2016 campaign, it is his position on trade that has presented one of the most unexpected challenges for his rival, Hillary Clinton, the likely Democratic nominee. In an election season animated by economic anxiety, Trump, a New York business mogul, bucked Republican orthodoxy and powerful business interests such as the U.S. Chamber of Commerce in an appeal to blue-collar Republicans that helped propel him t o victory in the GOP primaries.

Clinton, who scrambled to move left on trade during her tough primary fight against Sen. Bernie Sanders of Vermont, now finds herself again facing attacks on the issue — this time from Trump. He used his Pittsburgh-area speech to disparage her association with a pair of major trade agreements — one negotiated by President Bill Clinton’s administration and the other by President Obama’s while she served as secretary of state.

For Hillary Clinton, the risk is not necessarily losing support directly to Trump but rather not inspiring enough enthusiasm among rank-and-file union workers, whose turnout and ground-level organizing have traditionally been crucial for Democrats.

Clinton already has the endorsements of several of the nation’s largest labor organizations, including the AFL-CIO and the United Auto Workers, but faces the question of whether that organized support will be enough to hold the labor voting bloc together at a time when Trump has co-opted the traditional labor message about the perils of free trade and globalization.

“Some of our members if not support [him] agree with some of Trump’s statements,” said Joe Jacoby, 54, of Pennsauken, N.J., who serves as a union representative with Boilermakers Local 13. “Because they feel like they’re being hit hardest. Because their jobs are going away. Because it’s hard to find a good-paying job,”

Jacoby, who was at the McGinty rally, said he and the other union leaders support Clinton. McGinty also made clear she supports Clinton and emphasized that Trump does not have the right solutions to trade and jobs. But Jacoby acknowledged that Trump’s message is “going to have an impact.

“Trade agreements are a big part of what we’re arguing against, and he rings that bell,” he said. “You’ve got to give the man credit. When he talks about trade, it resonates with a lot of workers.”

Clinton’s potential weakness on trade is evident in her inability, so far, to consolidate some of the support that went to Sanders during the Democratic primary season. While Clinton dominated with endorsements from labor unions, plenty of locals went for Sanders.

He walked picket lines in Milwaukee and New York and frequently was introduced by union leaders who warned that only one candidate for the presidency had opposed the North American Free Trade Agreement, or NAFTA, inked by President Clinton in 1994. Unions have blamed that pact with Mexico and Canada for the elimination of hundreds of thousands of manufacturing jobs in the United States.

Sanders supporters also appreciated that the senator strongly opposed the Trans-Pacific Partnership, a 12-nation Pacific Rim accord led by the Obama administration. Hillary Clinton touted the TPP as the “gold standard” of trade deals in 2012 while leading the State Department, but she renounced her support after launching her campaign last year.

At least two unions that endorsed Sanders, the International Longshore and Warehouse Union and the United Electrical, Radio and Machine Workers of America, said they are unlikely to make an endorsement for the general election.

“The problem is that Clinton has been a free-trader her whole life, so we’re not going to endorse her,” said Peter Knowlton, president of the electrical-workers union. “We will be running an anybody-but-Trump campaign. We have many members in swing states, and our major goal is for Trump not to get elected — not to make a pitch for Hillary.”

The Teamsters, with 1.4 million members, also have not made a formal choice between Clinton and Trump. Teamsters President James Hoffa said that he hoped the contrast between the two candidates will become clearer after they release their platforms at their respective national party nominating conventions this summer.

“While trade is an important issue for our union, we believe any presidential candidate needs to take a stand for our country’s working men and women by supporting critical issues like pension reform and the protection of labor rights,” Hoffa said in a written statement to The Washington Post.

Even for the big labor groups that have gotten behind Clinton, much of their initial efforts have focused less on touting her merits on trade and more on trying to undermine Trump’s appeals to the working class. The AFL-CIO has produced a pair of online ads denouncing Trump’s integrity and sincerity on trade, with video of the mogul acknowledging that his clothes were manufactured in Asia.

“I think he’s tapped into the legitimate anger and frustration that a lot of working-class people are feeling,” AFL-CIO President Richard Trumka said in an interview in his office overlooking the White House. But Trumka added: “Look at what he does, not what he says. He could have an effect on trade by bringing all the products he makes overseas back home and have Americans produce them. But he doesn’t do that.”

Asked what he is doing to ensure the organization’s 12.5 million members will actively support Clinton and reject Trump, Trumka said: “You go out and talk to them. It’s face-to-face contact. It’s phone contact. It’s leafleting. It’s work-site visits.”

Labor unions that support Clinton suggested their backing is based more broadly on the policies she would implement than just her record on trade.

Erikka Knuti, a spokeswoman for the United Food and Commercial Workers International Union, said that Trump clearly “shuffled the deck” but that labor maintains a clear case against him — and for Clinton.

“Our endorsement is about what our members want,” Knuti said, citing collective-bargaining rights and the National Labor Relations Board. “That is stuff that’s really solidly in Clinton’s wheelhouse and not at all in Trump’s wheelhouse. Hillary has 30 years of public-service baggage and Trump has 30 years of PR and celebrity behind him. But who’s going to be for collective bargaining? It’s pretty clearly Hillary is. Who’s better for paid family leave? Hillary is.”

Weigel reported from Washington.