The trade pact between U.S. and Mexico announced Monday would build a wall to keep out cheap goods from China.

China has long been considered the “uninvited guest” to the North American Free Trade Agreement. Its entry into the World Trade Organization led to a massive increase in its exports to the U.S. and Mexico, resulting in huge trade imbalances.

More strikingly, trade with China displaced trade between the two North American nations. China has taken market share from the U.S. in exports to Mexico–and from Mexico in exports to the U.S. , according to a 2013 study by Enrique Dussel Peters, coordinator of the Center for China-Mexico Studies at National Autonomous University in Mexico, and Kevin Gallagher, professor of international relations at Boston University where he co-directs the Global Economic Governance Initiative.

Prior to China’s ascension to the WTO, the US supplied Mexico with 60.8 percent of its office machine and computer imports and 70 percent of the peripheral parts for those machines. A decade later, the U.S. share had fallen to 10 percent. During that period China’s market share went from 13 percent of the office machine import market to 44 percent, and 5 percent of the parts market to 58 percent.

“We find that by 2009, 84% of Mexico’s manufacturing exports to the US were under threat from China. By threat we mean sectors where China is gaining market share and Mexico is losing it. We also find that 96% of US exports to Mexico are under threat from China,” Peters and Gallagher wrote in a 2014 article about their study.

There is an eight to one ratio of Mexico’s imports from China to Mexico’s exports, according to Marcelo Ebrard, Mexico’s incoming foreign minister.

Even that likely understates the impact on China. U.S. Commerce Secretary Wilbur Ross has said that NAFTA opened a “back door” for Chinese products to enter the United States through Mexico and Canada.

Part of the problem has been NAFTA’s outdated rules of origin. When the agreement was drafted in the early 1990s, it did not anticipate the rise of China as a predatory, mercantilist manufacturing power. It did not foresee that Chinese manufacturers would seek to take advantage of Mexico’s access to U.S. markets by as many shipping parts and materials, to Mexico for eventual sale into U.S. markets. China is the second largest exporter of metals to Mexico, after the U.S.

The new deal would require 75 percent of the content in automobiles be sourced in North America to qualify for tariff-free treatment, up from 62.5% under NAFTA. It also requires that key materials used to make automobiles, such as steel and aluminum, be sourced in North America. Rule of origin for many products–including textiles, chemicals, and other steel-intensive goods–will be tightened, as well.

This should reduce the China threat in Mexico and the U.S., which is one reason the agreement could be a win for workers on both sides of the border.