ERIE, Pa. — Sean D. Wiley recalled the moment it hit him, hard, that the people he had known all of his life and represented in the Pennsylvania State Senate were abandoning his Democratic Party.

Union workers at the General Electric plant just east of here, which makes locomotives, told Mr. Wiley that they would vote for Donald J. Trump. Once Erie County’s largest employer, the plant has shed thousands of $34-an-hour workers and moved production to a nonunion factory in Texas.

In their desperation to hang onto jobs, General Electric’s workers embraced Mr. Trump even though his pledge to tear up trade deals to rebuild American manufacturing would seem to have little to do with their own situation, with jobs moving to another state.

Mr. Wiley, who lost his Senate seat in Harrisburg, the state capital, on Election Day, said he had warned voters “ad nauseam” during the campaign that Republicans in the legislature would pass an anti-union, “right-to-work” law, but it was to no avail.