Working around the clock for days past their deadline, haggard trade ministers announced they reached agreement on the ambitious Trans-Pacific Partnership just before dawn, capping five years of difficult talks led by the United States.

Spanning about two-fifths of the global economy, the hard-won deal aims to set the rules for 21st century trade and investment and press China, not among the 12, to shape its behavior in commerce, investment and business regulation to TPP standards.

Obama hailed the agreement as one that "strengthens our strategic relationships with our partners and allies in a region that will be vital to the 21st century."

"When more than 95 percent of our potential customers live outside our borders, we can't let countries like China write the rules of the global economy," Obama said in a statement.

In Canada, Prime Minister Stephen Harper praised the "historic" accord, saying it opens more access to the Japan market for Canadian farmers and resource sectors.

Australian Prime Minister Malcolm Turnbull also said it would deliver strong benefits for his country's businesses.

And in New Zealand, where there was disappointment at not achieving more openings to the country's prodigious dairy exports, Prime Minister John Key said it nevertheless meant "more jobs, higher incomes and a better standard of living."

- 'Trade deal for 21st century' -

The accord involves significant market openings, tariff cuts on thousands of products, and pledges to protect investors across the 12 countries: Australia, Brunei, Canada, Chile, Japan, Malaysia, Mexico, New Zealand, Peru, Singapore, the United States and Vietnam.

Japan has made major concessions to open its market wider to major food exporters such as Australia, New Zealand and the United States.

The United States agreed to lower its tariffs on Japanese car parts from non-TPP locations like China and Thailand, even though that will hurt TPP and NAFTA partners Mexico and Canada.

Canada opens up to dairy products from New Zealand; both Australia and Canada get higher sugar quotas in the United States.

But more broadly, the agreement establishes mechanisms to handle disputes between foreign investors and governments; requires governments to not discriminate between their own state companies and foreign investors in major contracts; and demands countries like Vietnam, Mexico and Malaysia improve labor standards.

It also addresses new issues like data trade and intellectual property that have not been covered in multilateral trade pacts of the past.

Canada Trade Minister Ed Fast called the deal "truly transformational, saying: "The magnitude and importance of rules for 21st century issues can't be underscored enough."

- Ratification challenge -

But as grueling as the negotiations in Atlanta, Georgia were, completed only at 5:00 am Monday, the heavy lifting was not over for many of the TPP governments.

They now must sell the pact to their people and parliaments for ratification, with many suspicious about a deal negotiated in intense secrecy and being delivered to them as an unmodifiable whole for an up-or-down vote.

That job promises to be particularly difficult in Washington, where Congress already sounds hostile and its review will come during the election season next year.

From powerful Senator Orrin Hatch on the right and Senator Bernie Sanders, a presidential hopeful, on the left, President Obama was challenged to demonstrate US business and workers will not suffer.

Hatch warned he will scour the deal "to determine whether our trade negotiators have diligently followed the law so that this trade agreement meets Congress's criteria."

Likewise in Canada, the TPP tradeaways are already issues in the October 19 general election.

The leftist New Democratic Party, currently trailing in the polls, said if elected it "would not consider itself bound" by the deal that "puts family farms at risk."

In New Zealand, acting Labor Party leader Annette King challenged the government over the pact that gave the dairy industry "only crumbs."

"The government must come clean now on what ugly compromises they have made behind closed doors," she said.

"The devil is definitely in the detail in these agreements."

Even in Malaysia, where securing passage should be easier, Trade Minister Mustapa Mohamed walked gingerly ahead of public review of the treaty, stressing it would not undermine the country's Bumiputera policies to help native Malay-owned businesses.

"Malaysia would never be party to an agreement that violated the nation's constitution or one that undermined the core policies instituted by the government to benefit the people," he said in a statement.