Donald Trump, who has made maligning illegal immigrants from Mexico a cornerstone of his presidential campaign, met with Mexican President Enrique Peña Nieto on Wednesday — striking a remarkably subdued and cooperative tone as he faced a world leader who forcefully opposes his signature proposals.

Yet just hours later in a major speech on immigration in Phoenix, the Republican presidential nominee had returned to the aggressive tenor that has defined much of his campaign. Repeatedly raising his voice to a yell, he said that “anyone who has entered the United States illegally is subject to deportation,” and he vowed to crack down especially hard on illegal immigrants who have committed other crimes.

With less than 10 weeks until the election, Trump increasingly has tried to adjust his pitch to appeal more to moderate voters, as polls show he has fallen solidly behind Democratic rival Hillary Clinton nationally and in battleground states. However, the visit here and the speech in Phoenix could provide a jarring contrast for voters and send a confusing message about the kind of president he would be.

Trump said at the joint news conference in Mexico that he and Peña Nieto didn’t discuss who would pay for his proposed wall along the U.S.-Mexico border, despite his long-standing vow to compel Mexico to foot the bill. He and Peña Nieto avoided direct confrontation in front of the cameras, airing their differences on immigration, border security and trade in cordial tones.

But later, Peña Nieto tweeted: “At the beginning of the conversation with Donald Trump I made it clear that Mexico will not pay for the wall.” The Trump campaign did not immediately comment on the apparently conflicting accounts.

On Aug. 31, Republican presidential candidate Donald Trump gave a speech about his plans to deal with illegal immigration. The Post's Rebecca Sinderbrand breaks down some of what he said and how it was received. (Sarah Parnass/The Washington Post)

Trump spokesman Jason Miller issued an opaque statement Wednesday evening saying the meeting “was not a negotiation. . . . It is unsurprising that they hold two different views on this issue, and we look forward to continuing the conversation.” Peña Nieto spokesman Eduardo Sanchez said that the president told Trump, “Mexico won’t pay for the wall,” but that his comments did not spur a discussion.

The address in Phoenix was considered a chance for Trump to clarify whether he still wants to forcibly deport all of the nation’s estimated 11 million illegal immigrants after sending mixed signals recently. He left that question unanswered — dismissing it as irrelevant — while also strongly suggesting that he would push to deport as many people as possible.

“The truth is, the central issue is not the needs of the 11 million illegal immigrants,” Trump said, arguing that “only the out-of-touch media elites think the biggest problems facing American society today is that there are 11 million illegal immigrants who don’t have legal status.”

He said that undocumented immigrants seeking legal status would first have to leave and try to return lawfully — a process that can take many years under current procedures. Trump said that he would have “zero tolerance” for illegal immigrants who have committed crimes beyond their immigration violations.

“We will issue detainers for illegal immigrants arrested for any crime whatsoever,” he said, going further than other Republicans who have called for felons to be deported. Later, he said he would create a “deportation task force” to deal with “the most dangerous criminal illegal immigrants” who have “evaded justice.”

He also proposed an“ideological certification” test to ensure that immigrants share Americans’ values, and promised not to issue visas to people coming from parts of the world where “adequate screening cannot occur.”

At one point, Trump said: “We’re like the big bully that keeps getting beat up.”

1 of 14 Full Screen Autoplay Close Skip Ad × Photos from Donald Trump’s trip to Mexico to meet with President Pena Nieto View Photos In his first formal international trip as the Republican presidential nominee, Donald Trump visited a country where he is broadly despised for his vilification of illegal immigrants. Caption In his first formal international trip as the Republican presidential nominee, Donald Trump visited a country where he is broadly despised for his vilification of illegal immigrants. Aug. 31, 2016 Republican presidential nominee Donald Trump, right, shake hands with Mexican President Enrique Pena Nieto after their joint statement at the Los Pinos presidential residence in Mexico City. Dario Lopez-Mills/AP Buy Photo Wait 1 second to continue.

The hastily arranged meeting in Mexico City was aimed at easing concerns among U.S. voters about his preparedness for the presidency, campaign aides said.

[Donald Trump’s Mexican news conference, annotated]

After an hour behind closed doors at Los Pinos, the official presidential residence and office, Trump and Peña Nieto strode out slowly to adjacent lecterns — in front of only the Mexican flag — to address the public about policy differences wider than the Rio Grande is long.

“We had a very substantive, direct and constructive exchange of ideas over quite a period of time,” Trump said. “I was straightforward in presenting my views about the impacts of current trade and immigration policies on the United States.”

At campaign rallies nationwide, Trump has a favorite call-and-response in which he asks his massive crowds who is going to pay for the wall he has promised he would build.

“Mexico!” his supporters shout back. In his Phoenix speech, he renewed his promise to build a wall and make Mexico pay for it.

But according to his account of the meeting with Peña Nieto, Trump passed on a chance to press the issue, apparently keen to play down what has become a very sensitive issue for many Mexicans and Americans.

“We did discuss the wall. We didn’t discuss payment of the wall. That’ll be for a later date. This was a very preliminary meeting,” the candidate said.

Peña Nieto also was tactful during his remarks, offering a polite and careful rebuke to many of Trump’s signature stances.

He cast illegal immigration and border security as a shared challenge but said that undocumented immigration has slowed in recent years. He also praised the merits of free trade; Trump has expressed deep skepticism about sweeping trade deals and has vowed to “rip up” the North American Free Trade Agreement.

[Donald Trump’s Mexico visit ends with Mexico basically accusing him of lying]

“I shared my strong view that NAFTA has been a far greater benefit to Mexico than it has been to the United States and that it must be improved upon to make sure that workers, and so important, in both countries benefit from fair and reciprocal trade,” Trump said.

Peña Nieto noted that he also had invited Clinton to visit, and he pledged to respect the electoral process of the United States.

Trump outlined five goals he has for the region: ending illegal immigration, creating a secure border, dismantling drug cartels, improving pay for workers and keeping jobs in the hemisphere.

The Republican nominee hit familiar notes about the loss of manufacturing jobs in the United States. But he didn’t blame Mexico as directly as in the past, suggesting that keeping jobs in the hemisphere is the goal.

“We must take action to stem this tremendous outflow of jobs from our country,” he said. “It’s happening every day, it’s getting worse and worse and worse, and we have to stop it.”

During Peña Nieto’s remarks, Trump stood with his hands clasped, and with a slight frown, while an interpreter spoke into his ear. When it was his turn to speak, Trump said it was a “great, great, honor” to be invited to Mexico, a country that he has regularly disparaged as “corrupt” and dangerous during his campaign.

He said he had “tremendous feelings” for Mexican Americans, not only his friends, but his Mexican employees. “I am proud to say how many people I employ,” he said. “They are tremendous people.”

When Trump began his campaign last summer, he cast illegal immigrants from Mexico as “rapists” and criminals and suggested that the Mexican government was sending them. Clinton sought to remind voters Wednesday about his controversial language and warned that he cannot simply paint over it with a quick stopover.

Speaking at the American Legion convention in Cincinnati before Trump’s meeting, Clinton said coalition-building and leadership will take more than a “photo-op.”

“It certainly takes more than trying to make up for a year of insults and insinuations by dropping in on our neighbors for a few hours and then flying home again. That is not how it works,” she said without naming her rival.

After the Mexico City event, Clinton campaign chairman John Podesta said in a statement that Trump had “choked” by not confronting Peña Nieto about his signature issue. Then he amended the statement following the differing accounts of paying for the wall: “It turns out Trump didn’t just choke, he got beat in the room and lied about it.”

[Mexicans express anger about Trump meeting]

Former Mexican president Felipe Calderón, Peña Nieto’s immediate predecessor, said after the news conference that Trump is “a hypocrite” and “a liar.” Are Mexicans “rapists,” he said, referring to Trump’s remarks last year, “or are we a wonderful, marvelous hard-working people,” as Trump said at Peña Nieto’s side? “I don’t believe in him. I think he’s lying,” Calderón told CNN.

Peña Nieto, who is deeply unpopular here, shocked his country and much of his government by inviting Trump for a personal visit. The invitation, Calderón said, “was a very bad move for Mexico. . . . It was completely unnecessary and inconvenient.”

Mexicans learned only late Tuesday that Trump would be visiting — and many were outraged about the invitation. How could a man who has proposed walling off the border, deporting millions, blocking remittances and undercutting Mexican jobs be welcomed in their capital?

Former and aspiring presidents, opposition rivals and regular citizens expressed anger and bafflement at the surprise guest. As one senior Mexican official put it, “This is not a winning proposition having him here.”

Using the joint appearance to make the case of Mexico’s economic importance to the United States, Peña Nieto rattled off trade and job statistics during the news conference, while mentioning that Trump’s commentary had “hurt” his country, and that his people, and millions of Mexicans in the United States are “honest and hard-working people.”

“They are good people. They respect family. They respect community life and they respect the law,” Peña Nieto said. “Mexicans deserve the respect of everyone.”

The U.S. Embassy in Mexico, through the Secret Service, was first informed Saturday of a possible visit by Trump, then was told Saturday night that the trip would not take place. On Sunday, it was informed by security personnel that the trip was back on.

State Department spokesman John Kirby said that the only contact between the Trump campaign and the Obama administration was with the Secret Service regarding security for the trip. The U.S. Embassy in Mexico “was not asked to provide any support or briefings for the visit,” Kirby said. “There’s no expectation that our ambassador or any embassy personnel are going to be participating in the visit in any way.”

It is not unusual for presidential candidates and nominees to travel abroad. The State Department offers only security assistance and, if requested, general briefings on major issues of interest and U.S. policy.

Trump was joined in the meeting by former New York mayor Rudolph W. Giuliani and Sen. Jeff Sessions (R-Ala.), who have become fixtures at his campaign rallies.

After shedding, for at least an afternoon, the combative tone that has become his calling card, Trump earned praise from strategists in both parties. Howard Wolfson, a former strategist and communications director for Clinton, tweeted: “If you believe Trump needed to pivot, moderate and look more Presidential, that event was a home run.”

Sullivan reported from Washington and DelReal from Phoenix. Anne Gearan in Cincinnati and Karen DeYoung and Robert Costa in Washington contributed to this report.