In a news conference with Pena Nieto at the White House, Obama said trade with Mexico brings important investment and jobs to the US. He said the United States sells more to Mexico than to China, India and Russia combined.
Obama said he has worked to deepen the relationship during his presidency.
"We're not just strategic and economic partners, we're also neighbors and we're friends," Obama said.
Pena Nieto said a good relationship with the United States is "essential" for his country and said he looks forward to a "frank, open dialogue" with whomever is elected.
More From This Section
Pena Nieto avoided questions about the wall, but has previously said that Mexico will not pay for the wall Trump proposes.
The two men also endorsed the Trans-Pacific Partnership trade agreement that both countries have signed on to, saying it would make the relationship between their countries even stronger. They said they have learned from the two-decade-old North American Free Trade Agreement, which Trump has heavily criticized.
The visit comes less than a month after Pena Nieto and Obama met in Canada during a summit of North America's leaders.
Obama's meetings with visiting foreign leaders are usually announced weeks in advance, but this visit was announced just last week.
The White House shrugged off suggestions that the visit was timed to highlight differences between Democrats and Republicans, particularly on attitudes toward Latinos.
"I think it's fair to say that almost anything that President Obama did on Friday would be viewed as a sharp contrast to the agenda that's being put forward by the other side," said White House press secretary Josh Earnest.