WASHINGTON (MarketWatch) — Is a 1994 trade deal with Mexico really as one-sided as President Donald Trump claims? Does Mexico benefit much more than the United States? A close look at trade between the two countries shows the answer is not cut and dried.

On Thursday, Trump quickly escalated tensions with Mexico over how to pay for a border wall and what the new president views as an unfair trade relationship.

In a pair of early-morning tweets, Trump called the 1994 agreement known as NAFTA a “one-side deal from the beginning” and suggested the pending visit by Mexican President Pena Nieto be canceled.

Nieto did exactly that and bowed out, less than a day after criticizing plans for a U.S. border wall. Then hours later the White House floated the idea of a steep tax on Mexican imports.

Both the U.S. and Mexico have benefited from the controversial trade agreement that went into effect under President Bill Clinton in 1994, but Mexico has arguably been the bigger winner.

After running a trade deficit with the U.S. from 1991 to 1994, Mexico moved to a surplus in 1995, and that’s been the case ever since. Mexico has become a major producer of automobiles, electronics and appliances, to go along with its status as a large oil exporter.

As a result, U.S. imports from Mexico soared from $65 billion when the North American trade deal was passed to around $295 billion in 2016.

The U.S. has been helped, too, especially in border states such as Texas. Exports to Mexico have climbed from $68 billion in 1994 to an estimated $235 billion in 2016.

Key Words:Lost a factory job? Don’t blame NAFTA or China’s joining the WTO, says economist Brad DeLong

As Trump pointed out, though, the U.S. is on track to run a trade deficit of close to $60 billion with Mexico in 2016, according to government data. That’s about 12% of the nation’s overall annual trade gap.

The trade deficit with Canada, the third member of NAFTA, is a much smaller $9 billion.

The industry in which Mexico has made the biggest gains since NAFTA is automobiles — often at the expense of the U.S.

Ford Motor Co. F, -0.68% and General Motors GM, -1.31% , with other car makers, have dramatically ramped up operations south of the border. In 2015, a record one-third of Mexican imports to the U.S. consisted of autos, engines and other parts.

Altogether, U.S.-owned companies and their affiliates employed 1.29 million Mexicans in 2015, generating $253 billion in sales, Bureau of Economic Analysis data show.

By contrast, Mexican firms operating in the U.S. employed just 78,000 workers and registered sales of $32.8 billion in 2015.

The relationship is not as one-sided as Trump suggests, though.

Also read: Border mayor wants Trump to invest in roads, not walls

The U.S. has invested more than $90 billion in Mexico, millions of American jobs are tied to trade with the southern neighbor, and rising wealth in Mexico has actually curbed immigration from that country.

A study from Pew Research, for instance, suggests that more immigrants have returned to Mexico since the end of the Great Recession in 2009 than have migrated to the U.S. The vast majority of immigrants arriving in the U.S. illegally now come from central America.

If, as Trump himself has said, a prosperous Mexico is good for the United States, a reworked trade deal that hurts the Mexican economy could also put more pressure on Mexicans to try to enter the U.S. illegally.