HARRISBURG, Pa. (AP) — Democrat Bob Casey has won a third U.S. Senate term from Pennsylvania, beating Republican Rep. and Donald Trump supporter Lou Barletta in a state the president won two years ago.

Casey's victory in Tuesday's election gives him another six-year term in office and ensures that Trump will have another swing state opponent in the closely divided Senate.

The 58-year-old son of the late former governor has now won six statewide elections, including wins in races for state treasurer and auditor general.

The race was a far cry from Pennsylvania's record-breaking $170 million race in 2016, coming at under $40 million while control for the Senate was waged in perhaps a dozen other states.

Barletta, 62, is one of Trump's biggest allies on Capitol Hill and drew two presidential visits to Pennsylvania to help rally support for his candidacy.

But Barletta never gained traction against Casey, and was heavily outspent while getting virtually no outside help from GOP groups to overcome Casey's heavy fundraising advantage and built-in recognition as a household name in Pennsylvania politics.

On the campaign trail, Casey pounded Trump's tax-cutting law as a giveaway to the wealthy and corporations while middle-class wages stagnate. Casey opposed Trump's immigration policies and voted against Trump's nominees for Supreme Court while he stitched together support from liberals and his longtime allies in organized labor.

Casey also sounded alarm bells over what he framed as threats to Medicaid, Medicare and Social Security under GOP-controlled Washington.

Barletta was first elected to Congress in 2010, catapulted by his efforts to combat illegal immigrants while serving as mayor the small northeastern city of Hazleton.

Trump asked Barletta to run, and Barletta campaigned on Trump's policies and record, particularly immigration, where their views dovetailed.

But Barletta failed to reconstruct the coalition of Republicans and conservative Democrats that had helped Trump become the first Republican presidential candidate to win Pennsylvania since 1988.

The final weeks of the campaign were trying for Barletta. His 18-month-old grandson, a twin, was diagnosed with cancer and his brother died. In the midst of this, Casey launched a series of statewide TV ads accusing Barletta of voting in Congress to let insurers strip coverage for pre-existing conditions.

Barletta cried foul, saying an ad featuring a woman whose twin daughters were diagnosed with cancer was particularly cruel to his family because it mirrored his grandson's plight.

Casey apologized if the ad had caused Barletta and his family any pain. Any similarity had been unintended, Casey said, and the campaign took down the ad in the Scranton TV market. But Casey declined Barletta's request to take down the ad in the rest of the state and his campaign said flatly that Barletta "will be held accountable" for his votes.