In this April 28, 2010, file photo, men look for a place to sleep in a crowded shelter for migrants deported from the United States, in the border city of Nogales, Mexico. (Gregory Bull/AP)

More Mexicans are leaving than moving into the United States, reversing the flow of a half-century of mass migration, according to a study published Thursday.

The Pew Research Center found that slightly more than 1 million Mexicans and their families, including American-born children, left the United States for Mexico from 2009 to 2014. During the same five years, 870,000 Mexicans came to the United States, resulting in a net flow to Mexico of about 140,000.

The desire to reunite families is the main reason more Mexicans are moving south than north, Pew found. The sluggish U.S. economic recovery and tougher border enforcement are other key factors.

The era of mass migration from Mexico is “at an end,” declared Mark Hugo Lopez, Pew’s director of Hispanic research.

The finding follows a Pew study in 2012 that found net migration between the two countries was near zero, so this represents a turning point in one of the largest mass migrations in U.S. history. More than 16 million Mexicans moved to the United States from 1965 to 2015, more than from any other country.

The findings counter the narrative of an out-of-control border that has figured prominently in the presidential campaign, with Republican Donald Trump calling for Mexico to pay for a fence to run the entire length of the 1,954-mile frontier. Pew said there were 11.7 million Mexicans living in the United States last year, down from a peak of 12.8 million in 2007. That includes 5.6 million living in the country illegally, down from 6.9 million in 2007.

In another first, the Border Patrol arrested more non-Mexicans than Mexicans in the 2014 fiscal year, as more Central Americans came to the United States, mostly through South Texas. Many of them turned themselves in to authorities.

The authors analyzed U.S. and Mexican census data and a 2014 survey by Mexico’s National Institute of Statistics and Geography. The Mexican questionnaire asked about residential history and found that 61 percent of those who reported living in the United States in 2009 but were back in Mexico last year had returned to join or start a family. An additional 14 percent had been deported, and 6 percent said they returned for jobs in Mexico.