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 U.S. for Mexico from 2009 to 2014. During the same five years, 870,000 Mexicans came to the U.S., resulting in a net flow to Mexico of 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.

"This is something that we've seen coming," Lopez said. "It's been almost 10 years that migration from Mexico has really slowed down."

The findings counter the narrative of an out-of-control border that has figured prominently in U.S. presidential campaigns, with Republican Donald Trump calling for Mexico 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 U.S. last year, down from a peak of 12.8 million in 2007. That includes 5.6 million living in the U.S. 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 U.S., mostly through South Texas, and 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 U.S. 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.

Dowell Myers, a public policy professor at the University of Southern California, said it's lack of jobs in the U.S. — not family ties — that is mostly motivating Mexicans to leave. Construction is a huge draw for young immigrants, but has yet to approach the levels of last decade's housing boom, he said.

"It's not like all of a sudden they decided they missed their mothers," Myers said. "The fact is, our recovery from the Great Recession has been miserable. It's been miserable for everyone."

Also, Mexico's population is aging, meaning there's less competition for young people looking for work. That's a big change from the 1990s, when many people entering the workforce felt they had no choice but to migrate north of the border, Myers said.

While the U.S. economic recovery is sluggish, Mexico has been free in recent years from the economic tailspins that drove earlier generations north in the 1980s and 1990s. While many parts of Mexico suffer grinding poverty and violence, others have become thriving manufacturing centers under the North American Free Trade Agreement.

Automakers including Volkswagen AG, Ford Motor Co. and General Motors Corp. have built plants across central and northern Mexico that employ thousands, spawning auto-parts plants and other ripple effects. Highways and rail lines that connect to the world's largest economy north of the border have attracted more investors.

"The main reason for my return is family," José Arellano Correa, a 41-year-old Mexico City taxi driver who came back from the U.S. in 2005. "I could help them while I was there, but family comes before money."

Farmworkers recruited from Mexico to harvest U.S. crops had followed the seasons back and forth across the border until 1965, when the U.S. imposed numerical limits on Latin American immigrants for the first time, launching new waves of illegal immigration that flowed north for decades thereafter.

A federal law passed in 1986, four years after Mexico's economy convulsed, led to a more fortified border and legal status for millions of migrants. Policies toughened even more after 9/11, with the Border Patrol doubling in size and the U.S. erecting hundreds of miles of fences, and Arizona led a backlash in state capitols as Mexicans moved beyond traditional destinations like Los Angeles and Chicago, settling in towns throughout the South and Midwest.

Many Mexicans in the U.S. have become frustrated and fearful as efforts to overhaul immigration laws stalled in Congress and President Barack Obama deported roughly 2 million people during the first five years of his administration. Obama's 2014 order shielding many others from deportation remains blocked in court.

Mexicans who remain in the U.S. also seem more detached from their homeland than before. Pew said their median age was 39 years in 2013, compared to 29 in 1990. More than three in four had been in the U.S. for more than a decade, compared to only half in 1990. And only 35 percent of adults in Mexico say they have friends or relatives they regularly communicate with or visit in the U.S., down 7 percentage points from 2007, Pew found.

Guadalupe Romo, 49, has lived in Fresno, California, for 26 years and has no plans to leave.

"We have our life here," she said at Fresno's Mexican consulate. "There's no point in going back to Mexico."