Ministers appeared close to sealing the world's biggest trade reform for two decades on Friday after India, the most vocal holdout, endorsed a draft text presented by the head of the World Trade Organisation.
The deal, thrashed out at talks on the Indonesian island of Bali, would lower trade barriers and speed up the passage of goods through customs.
Analysts estimate that over time it could boost the world economy by hundreds of billions of dollars and create more than 20 million jobs, mostly in developing countries.
Failure would have represented a body blow to the 159-nation WTO, formed in 1995 and still without a major trade deal to its credit after many years of negotiating fiascos.
"It is a victory for the WTO and for the global community to have arrived at a mature decision," commerce and industry minister Anand Sharma told reporters . "We are more than happy. It is a great day. It is a historic day."
The deal requires unanimous support, and a potential veto could still come from Cuba, whose representative banged the table and shouted at WTO chief Roberto Azevedo after the meeting where his draft agreement was distributed to all the members, a participant at the meeting said.
Cuba has been consistently demanding the United States lift its economic embargo of the Caribbean island as part of the Bali agreement, but trade diplomats say it has made the same demand for decades and they do not expect it to block a deal.
Heads of delegation were to resume informal talks in the early hours of Saturday, but a diplomat said the meeting had been delayed by an hour because of last-minute concerns about the wording of a compromise on food subsidies.
That is the vital issue for India, which this year announced a massive programme for stockpiling food to feed to the poor, in breach of the WTO rules on subsidies.
Another diplomat said the delay was caused by Cuba consulting with Azevedo.
Azevedo, a Brazilian diplomat, took the helm of the WTO in September and immediately launched a punishing regime of round-the-clock talks and "whatever works" diplomacy. Even so, the outcome had appeared in grave doubt as recently as Thursday.
If agreed, the reform would slash red tape at customs around the world, give improved terms of trade to the poorest countries, and allow developing countries to skirt the normal rules on farm subsidies if they are trying to feed the poor.
It would also revive confidence in the WTO's ability to negotiate global trade deals, after it consistently failed to clinch agreement in the Doha round of talks that started in 2001 and proved hugely over-ambitious.
As the Doha round stuttered to a halt, momentum shifted away from global trade pacts in favour of regional deals such as the Trans-Pacific Partnership that the United States is negotiating with 11 other countries, and a similar agreement it is pursuing bilaterally with the European Union.
Failure in Bali would have led to a more divided world, with regional blocs reversing the WTO's globalising goals, some experts say.
The "Bali package" now on the table secures a handful of elements of the Doha round that were thought to be doable and declares a "strong resolve" to pursue agreement on the rest.
India's concerns that the Bali deal would give only a temporary shield to its food stockpile plan were resolved with wording that promised a search for a more permanent solution.
"The food security fix is something out of 1984, George Orwell would be proud," said Simon Evenett, professor of international trade at the Swiss University of St Gallen.
"The food security text is so contradictory that there must be an informal understanding among the big players as to what it really means."
Many diplomats had predicted Sharma, whose government is entering a bruising electoral battle, would use Bali as a platform where India could be seen to stand against the rich world in defence of the poor.
But India was under pressure to accept an eventual compromise, because failure of the Bali package would leave its food subsidy programme exposed to trade disputes that could lead to billions of dollars in trade sanctions.
The meat of the Bali deal is an agreement known in WTO jargon as "trade facilitation": streamlining and standardising customs and port procedures to speed trade globally.
A study by the Washington, D.C.-based Peterson Institute of International Economics estimated it would inject $960 billion into the global economy and create 21 million jobs, 18 million of them in developing countries.