WASHINGTON -- Sen. Pat Toomey (R., Pa.) said Wednesday he will oppose the Trans-Pacific Partnership, a major trade deal pending with Pacific Rim nations, marking a stark reversal for a free-market conservative facing a difficult reelection.

Toomey has long promoted the benefits of international trade and voted last year for a measure seen as crucial to completing the new pact. But in a Pittsburgh Post-Gazette op-ed, the senator wrote that the details of the Trans-Pacific Partnership fall short when it comes to opening international markets for Pennsylvania businesses. His stand comes after populist anger against such trade deals played a major role in the rise of GOP presidential nominee Donald Trump.

"Good deals require good negotiations," Toomey wrote, adding that this agreement would not protect innovations developed by Keystone State pharmaceutical companies or open up markets to the state's dairy farmers. "In the TPP, the Obama administration has not gotten a good enough deal for Pennsylvania workers."

Toomey's remarks arrive as public polls show him falling behind Democratic challenger Katie McGinty in one of the country's most crucial Senate races. They also come after months of rage against international trade fueled support for Trump and Bernie Sanders, and forced Democratic nominee Hillary Clinton to reverse course on the pending deal. McGinty has opposed the TPP and blasted Toomey over his stand on it.

"Pat Toomey has spent his entire career pushing bad trade deals and policies that ship Americans jobs overseas, so nobody is buying this ridiculous flip flop," McGinty said in a statement.

The TPP, signed by 12 nations earlier this year but awaiting ratification by Congress and officials in other countries, seeks to open up trade and covers issues such as tariffs, intellectual property and workers' rights. It involves nations that account for roughly 40 percent of the global economy, including Japan, Mexico and Australia.

Toomey last year sang the praises of the potential deal, saying it would expand markets for Pennsylvania goods, create jobs and give the U.S. more influence over the economy in a region where China is flexing its muscles. In May 2015 he voted in favor of so-called "fast-track authority" for President Obama, a measure seen as crucial to helping the administration seal the pact.

Supporters and opponents of the deal saw that vote as a proxy fight over the fate of the TPP.

Once the fast-track plan cleared the Senate, a Toomey news release said "we are a big step closer toward creating more jobs, lifting wages, and boosting economic growth for Pennsylvania. He added that administration officials had assured him that if the "Trans-Pacific Partnership agreement is enacted, our state would likely see a further surge in exports."

But Toomey's op-ed Wednesday argued that the final deal does not meet those goals. Writing in the largest newspaper in Western Pennsylvania, where many blame international trade for economic decline, he said the U.S. "must not abandon trade" and warned against political demagoguery on the issue,  but that "we should not pass a flawed deal just to get a deal done."

Republicans have pointed out that McGinty, as a top environmental aide in the Clinton administration, had praised a controversial trade deal then, the North American Free Trade Agreement (NAFTA). As she has run for senate, however, she has consistently voiced opposition to TPP.

You can follow Tamari on Twitter or email him at jtamari@phillynews.com.