ATLANTA -- Ending seven years of stop-and-start negotiations, officials from 12 Pacific Rim countries clinched early Monday a free-trade agreement that will allow two-fifths of the world’s goods and services to move more easily -- but not entirely freely -- across national borders. The pact, known as the Trans-Pacific Partnership, also poses a challenge to China, by creating rules for commerce on its doorstep that Asia’s fast-rising power played no role in writing.

Wrapping up six days of round-the-clock talks in an Atlanta hotel, around 5 a.m. EDT negotiators hosted by U.S. Trade Representative Michael Froman hashed out their remaining differences on the politically fraught and exceedingly arcane issues of patent rules and dairy trade with a series of compromises to finalize the 30-chapter agreement.

“We’ve been able to conclude what is a truly ambitious comprehensive and high-standard agreement. It’s a major milestone,” Froman said. “This agreement is good across the economy for manufacturing, for agriculture, for services, for entrepreneurs and inventors, for creative artists, for enhancing access to the fruits of innovation.”

The Atlanta result, though the product of painstaking, highly technical talks, came about thanks to domestic realities that emerged for the first time this year.

Signaling his commitment to the TPP, President Barack Obama persuaded the U.S. Congress to approve “fast-track” negotiating authority, which strengthens his hand in negotiations by ensuring lawmakers can’t amend the pact, only vote it up or down. The TPP is part of Obama’s rebalancing of U.S. foreign policy toward Asia, a goal since early in his presidency.

Sen. Orrin Hatch, the Utah Republican who chairs the powerful Senate Finance Committee, suggested that Froman had squandered a “once-in-a-lifetime opportunity” to make a good deal, implying that Republicans could break with Obama on an issue that has previously been a rare point of agreement.

“While the details are still emerging, unfortunately I am afraid this deal appears to fall woefully short,” Hatch said.

A 2012 estimate by the Peterson Institute for International Economics put the income gains from a TPP at $295 billion, including $78 billion in the United States, thanks to increased exports. Consumers also could benefit in the former of lower prices. The numbers obscure, however, the dislocations that often come with freer trade. For example, greater access to the U.S. dairy market could also accelerate a shakeout currently driven by low global prices. The United States sought to cushion the elimination of U.S. tariffs on vehicles by phasing the cuts in over up to 30 years.

Japanese Prime Minister Shinzo Abe is trying to use the pact to bolster his domestic reform agenda well in advance of parliamentary elections next year. And Canadian Prime Minister Stephen Harper, facing his own elections in less than two weeks, risked angering his country’s dairy farmers to preserve Canada’s spot in the pathbreaking accord.

Domestic politics will still affect the TPP's fate. The U.S. Congress will now be asked to approve the agreement during an election year, forcing Democrats to choose between Obama and organized labor, a core constituency that opposes it. Donald Trump, the Republican front-runner, months ago denounced the Pacific trade deal as “so pathetic and so bad.” And Hillary Clinton, the leading Democratic candidate, has walked back her initial support for the TPP as her chief challenger, Sen. Bernie Sanders, staunchly opposes it.

A change of government in Ottawa could upend Canada’s position on the pact. Tom Mulcair, the New Democrat challenging the Conservative Harper for the prime minister’s post, opposes the trade deal.

Froman offered a measured message to China, whose economic clout shadows the entire Asia-Pacific region, but alluded to rules on open Internet access and labor rights to suggest that TPP will steer the region in a different direction than Beijing might like.

“We think it helps define the rules of the road in the Asia-Pacific region that’s consistent with the interests and values we share.”

Akira Amari, the Japanese economy minister, pushed a tougher line, saying that if China ever wanted entry into the trade deal, it would not be able to block internet access and other “managerial resources” that companies need to thrive. “TPP will be the global standard for the 21st century,” Amari said.

The issue of patent protection for cutting-edge pharmaceuticals known as biologics vexed the talks at every step, with the United States endorsing the drug industry's position that only tough laws against imitators will keep money flowing into new research. Australia, with a government and public skeptical of rigorous protection for therapies so new that few are on the market, opposed the United States tooth and nail.

Much of the late-night diplomacy involved Froman and his Australian counterpart, Andrew Robb, as they wrestled with how long drug firms can keep data on clinical trials confidential, a "lockup period" that raises the value of patents because competitors can’t use the information to develop similar therapies. Companies such as Amgen and Pfizer have invested heavily in research on biologics, so called because they use living organisms to treat illnesses.

Froman, mindful that the pharmaceutical industry’s deal would help the pass Congress, backed off its demands for a 12-year lockup -- current U.S. law -- but refused to accept Australia’s five-year rule. Intense talks aimed at a solution melding the five years with an additional three in which regulators have flexibility to accept applications for similar drugs but keep them off the market for an additional three.

Burcu Kilic, research director for the Access to Medicines Project at Public Citizen, said the U.S. concession still leaves poorer countries with too-stringent rules that will limit availability of new pharmaceuticals.

“Call this ‘po-tay-to’ or ‘po-tah-to,’” Burcu said. “It’s eight years, and it’s unacceptable.”

 The debate is further complicated by presidential politics, current and future. Obama’s administration has sought to cut the U.S. lockup period to seven years, which Clinton has endorsed. The Republican-controlled Congress has refused.

“This was a red-line issue for us, and I said all along we’re not going to change the five years, and we’re not going to change our system,” Robb told reporters. “And that’s still the case.”

Conflicting demands of politically influential dairy farmers from New Zealand to Canada to Japan to New England ate up dozens of hours in Atlanta, where negotiators immersed themselves in the minutiae of trade in milk powder, whey protein and cheese. New Zealand and Australia, dairy export powerhouses, sought better access in a sector long coddled by a network of tariffs, subsidies and quotas.

They faced formidable opposition from Canada, which has federal elections in less than two weeks, thanks to the country’s system of limiting supply to boost the incomes of dairy farmers, who are concentrated in the biggest provinces, Ontario and Quebec. Harper vowed to keep Canada in the historic agreement, but struggled to convince farmers, or provincial ministers, who descended on Atlanta to stiffen the spine of their negotiators. In the end, the agreement carves out more opportunities for dairy exporters, but doesn’t create anything approaching free trade for milk products.

New Zealand Trade Minister Tim Groser, who helped originate the idea of TPP with an academic paper, spoke vividly of the “ugly compromises” that every country had to accept to complete the agreement.

“When we say ugly, we mean ugly from each perspective -- it doesn't mean ‘I've got to swallow a dead rat and you're swallowing foie gras,’” Groser told reporters. “It means both of us are swallowing dead rats on three or four issues to get this deal across the line.”