By MARC LEVY, Associated Press

HARRISBURG, Pa. (AP) — In a fight for his political life, Republican U.S. Sen. Pat Toomey is abandoning a major international trade deal that has emerged as a divisive campaign issue.

Announcing his opposition to the Trans-Pacific Partnership trade agreement puts the Pennsylvania senator more in line with labor unions and Democrats, including his challenger, Katie McGinty, who say the deal will drain jobs from the U.S. Democratic presidential nominee Hillary Clinton and her Republican rival, Donald Trump, have opposed it, too.

However, it puts Toomey out of step with Republican Senate leaders and a major Toomey backer, the U.S. Chamber of Commerce, on the deal involving the U.S. and 11 other Pacific rim countries, including Australia, Canada, Japan, Malaysia and Vietnam.

Polls show a neck-and-neck race between the first-term Toomey and McGinty, who has held various high-ranking posts in state and federal government. Millions of dollars in TV ads by outside groups are pouring into the contest, which could tip control of the chamber in the Nov. 8 election.

McGinty's campaign quickly called Toomey's opposition to the TPP a "flip flop" on a career spent supporting free-market principles and international trade deals.

In a sign of the unpopularity of trade deals in this election season, Clinton — who promoted the deal as the "gold standard" of trade agreements when she was secretary of state — also turned against it as a candidate.

McGinty, as a member of President Bill Clinton's administration in 1994, defended the then-newly signed North American Free Trade Agreement, but in this campaign, she has hammered trade deals as bad for domestic manufacturing jobs and the middle class.

Toomey wrote in an editorial published Wednesday in the Pittsburgh Post-Gazette that the deal would make it too easy for other countries to steal innovations — He mentioned Pennsylvania's life sciences and pharmaceuticals industries — and said it does not satisfactorily open up markets for dairy products.

"I have brought these and other problems to the attention of the Obama trade negotiators, but regrettably, they have failed to address them," Toomey wrote. "As it now stands, TPP is not a good deal for Pennsylvania. I cannot support it. ... We should dump the TPP and return to the negotiating table to get an agreement that would create jobs and economic growth here at home."

Despite President Barack Obama's push for action on it, Republican leaders in the Senate and House have said the deal lacks the votes to pass, and it is highly unlikely lawmakers will vote on it this year.

Toomey previously had said only that he had not decided whether to support the TPP, his aides said. Toomey's office said he has been reviewing the agreement since a copy of it was made available to lawmakers last October, but he thought it important to take a position now since the Obama administration notified Congress on Friday that it would send over the TPP bill.

McGinty's campaign pointed to an April 2015 interview on MSNBC in which he predicted the deal would boost economic and job growth in the U.S.

"The reality is, this trade agreement is going to knock down barriers to allow us to export more manufactured goods from Pennsylvania. It's definitely going to increase our ability to sell agricultural products overseas. It's going to help to protect the intellectual property of some of our really terrifically dynamic companies, like the pharmaceuticals, the medical device companies," Toomey said in the interview.

In 2015, Toomey backed legislation that allowed the TPP to be approved by a simple majority without opportunities to amend it in what was widely viewed as a test vote for the TPP. In 2011, Toomey voted for free trade agreements with South Korea, Colombia and Panama.

U.S. Sen. Bob Casey, a Pennsylvania Democrat who is a favorite of labor unions, opposed both bills and he opposes the TPP, his office said.