The agreement to refrain from new protectionist measures until the end of 2014 as part of world leaders' efforts to foster global growth was included in the final G20 communiqué.
Mexican President Felipe Calderon said it was hard won and struck only at the very end of two-day talks in the Pacific resort of Los Cabos.
"There was resistance from some countries but beyond that we did manage to get a consensus and arrive at an agreement," he told a news conference after the meeting.
Brazil, Argentina and South Africa had resisted extending the trade pledge beyond its current expiry at the end of 2013, while other countries wanted to push it back to 2015, a diplomat with knowledge of the G20 trade talks said. The deadlock was broken by Russian President Vladimir Putin, the diplomat said.
Ahead of the summit, Japan and the European Union had sent strong warnings that free trade was under threat as some countries respond to slowing growth by trying to protect their domestic industries.
"The EU is sounding the alarm regarding a worrisome rise in protectionism," EU President Jose Manuel Barroso said as G20 members arrived in Los Cabos.
Japan's Prime Minister Yoshihiko Noda called for world leaders to stamp out any efforts to lessen free trade. "I see signs of protectionism emerging in the G20 debate, so we should deliver a message to counter (that)," he told reporters.
Fearful that trade protectionism would slow global growth, G20 leaders at the height of the financial crisis in November 2008 first pledged to refrain from erecting any new trade barriers, often used to shield domestic businesses from world competition at times of economic stress.
Despite that effort, a World Bank report released on Sunday found that G20 nations have accounted for the vast majority of the more than 1,000 new protectionist measures that have been introduced between November 2008 and March 2012.
Brazil, for instance, has outraged fellow G20 partner Mexico by renegotiating a car export agreement earlier this year, and is also mulling steps to protect its tiny domestic wine industry which may raise tariffs on many imported wines from countries including Chile, France and Spain.
And it is not alone: Argentina, another G20 country, has slapped tough controls on imports in a bid to keep factories open and prop up the trade surplus in Latin America's third-biggest economy.
The United States has complained to the World Trade Organization that China is backsliding on the path of trade openness and economic reform that marked its entry to the World Trade Organization in 2001.
Brazilian President Dilma Rousseff launched a counter-offensive on trade at the G20 summit by proposing to re-open by 2014 the stalled Doha round of global negotiations to lower trade barriers. The idea failed to win traction with other G20 leaders.
"Some countries have agricultural subsidies, some countries think that there is protectionism in services, others saw problems in industry," she told reporters. "It's obvious that there is a lot of resistance to reopening the Doha round."
The Doha round was launched more than 10 years ago with the goal of helping poor countries prosper through trade. However, bitter divisions over how much developed countries should cut farm tariffs and subsidies in exchange for developing countries opening their markets have prevented a deal.
Business lobby group the International Chamber of Commerce warned that the increasingly protectionist climate could derail efforts to stimulate to world economic growth and development, a message shared by business leaders meeting on the sidelines of the G20 summit.
"We believe in free trade and free investment, and that's key to promote growth in the global economy," said Kimberly Clark Mexico chief executive Pablo Gonzalez.
"We should all combat those decisions and commit ourselves to open trade and to open investment."
Meanwhile, the United States pushed ahead on several trade initiatives on the sidelines of the G20 summit. U.S. President Barack Obama said that America and the European Union took the next steps toward broadening their trade relationship. The two sides are working on a possible trans-Atlantic trade pact.
Japan and Canada also joined the Trans-Pacific Partnership, an initiative championed by the United States aimed at creating a new free-trade zone.
Copyright @ Thomson Reuters 2012