THE WAVE of immigration from Mexico that began four decades ago, most of it unauthorized, has ended, possibly for good. As a report from the Pew Hispanic Center confirms, net migration from Mexico to the United States sank to about zero in the past five years. The number of Mexicans living in the United States without documents shrank from 7 million in 2007 to 6.1 million last year. Causes include tougher U.S. border enforcement and fewer U.S. jobs, especially in construction.

Did the North American Free Trade Agreement (NAFTA) play a role? President Bill Clinton pushed the controversial pact through Congress in 1993, arguing that slashing tariffs would create jobs and increase incomes in Mexico, resulting in “much less pressure on them to come to this country in the form of illegal immigration.” Has NAFTA finally fulfilled this promise?

Yes and no. Actually, the number of Mexicans living illegally in the United States shot up from 2.5 million in 1995, the year after NAFTA took effect, to 11 million in 2005. The main reason was the booming U.S. economy, which generated huge demand for labor just as the share of Mexico’s population aged 15 to 39 — prime migration years — was peaking at about 75 percent.

Migration plummeted after 2005 because of reduced U.S. demand for labor and the slowing of Mexican population growth — but also because NAFTA started to pay off in the form of dynamic new export industries in Mexico such as automobile manufacturing. Analysts suggest the gap in wages between the United States and its southern neighbor, while still wide, has narrowed to the point where staying home is economically rational for a growing number of Mexican workers.

NAFTA encouraged both the United States and Mexico to make optimal use of their scarce resources. In the short run, this shifted jobs and income within each society and between them. This inherently disruptive process doubtless caused Mexicans who lost out to seek opportunity in the United States.

But over time, NAFTA helped make Mexico more efficient and, hence, wealthier. It formed part of a broader restructuring that has transformed Mexico from the underdeveloped, authoritarian country it was 30 years ago to the increasingly middle-class democracy it is now.

The gross domestic product per capita in Mexico was $12,400 in 2010, up about 21 percent in real terms since 1980. Infant mortality is down from 79.4 per 1,000 live births in 1970 to 14.7 in 2009.

Practically every Mexican home has electricity; only 41.5 percent did in 1970. As educational levels have risen, the birth rate has dwindled to roughly that of the United States. There may never again be legions of Mexican jobless desperate to migrate, as in the ’80s and ’90s.

Yes, Mexico is wracked by drug-related violence; income inequality remains high. Yet in addition to being richer, Mexico is more politically developed than before NAFTA; its current problems can’t overturn what has become one of the most vibrant multiparty systems in the Americas.

The waning of unauthorized migration may ease a perennial sore point in U.S.-Mexican relations, enabling both countries to deepen their cooperation, of which NAFTA is, on balance, a worthy example.