In the early 1990s, a young scientist named Claudia Sheinbaum moved with her family from Mexico City to Northern California, where she studied at the Lawrence Berkeley National Laboratory.

She lived in housing provided by Stanford University with her two small children and her husband, who was pursuing a Ph.D. there. For four years, Ms. Sheinbaum immersed herself in a new life as an immigrant academic in the United States.

She audited a class taught by a future Mexican foreign minister. She landed on the front page of The Stanford Daily student newspaper for protesting the North American Free Trade Agreement. She found friends who missed Mexico as much as she did. And to people who knew her, she seemed entirely at ease in California, navigating the world of American academia.

“They could have been professors, they could have made their lives here,” said Alma González, a close friend of Ms. Sheinbaum’s in California. “But they decided to return.”

Now, three decades later, she has been elected the next president of Mexico, and is on the verge of becoming the first woman to lead the country. She takes office in October. The next month, Americans will vote to either keep a president who has stabilized relations with Mexico, or return to office a leader who has threatened and disparaged the country.

At such a decisive moment, Ms. Sheinbaum’s time in the United States and her dealings with American officials throughout her career offer crucial clues about how she will handle the biggest issues in the relationship with Washington.