When New York and New Jersey officials came to the Oval Office last September to lobby President Trump on a $30 billion tunnel, they found the president in fine fettle.

The president asked detailed questions about the tunnel, bemoaned the city’s airports, bragged about his construction record, boasted about the length of his private plane, referred to New York Gov. Andrew M. Cuomo (D) as “my governor” and shook Senate Minority Leader Charles E. Schumer’s hand so many times that others laughed.

Officials left thinking Trump was on board with federal funding for the Gateway project, seen as a critical infrastructure for the millions who commute into New York City. Transportation Secretary Elaine Chao also told New York officials for months in 2017 that the project was a top priority, two people familiar with her comments said. The project had also been listed as a high priority in a Trump transition document.

“It was almost like he was saying to ask for more money,” said Rep. Peter T. King (R-N.Y.), who was at the meeting. “We’ve heard nothing negative since then.”

But Republicans and Democrats alike were startled to learn Trump had told House Speaker Paul D. Ryan (R-Wis.) on Wednesday before a ceremony for the Rev. Billy Graham to not include the project in a large spending bill expected to pass later this month.

The comment surprised Ryan, who was not expecting to address a subterranean New York and New Jersey construction project in a holding room of the Capitol before the Graham memorial. In fact, Ryan had given little thought to the tunnel and was deferring to appropriators, including Rep. Rodney Frelinghuysen (R-N.J.), according to senior Hill officials.

The project is widely considered to be among the most pressing and expensive infrastructure needs in the country. Transportation problems in New York have been exacerbated by a booming population, damage from Superstorm Sandy in 2012 and not enough investment from state and local leaders.

The Trump administration threw the project into doubt late last year by casting aside an agreement reached during the Obama administration that would have the federal government cover half the project’s cost. It had previously been stalled after New Jersey Gov. Chris Christie (R) pulled money from the project.

“Gateway is essential to maintaining the economic engine of the New York region — which matters to the whole country,” said Howard Glaser, a transportation policy fellow at Hunter College in New York and a former director of operations for Cuomo. “The ability to commute to Manhattan from the west has fueled job growth in the city. . . . The system does not have the capacity for projected growth.”

Trump’s maneuver, which pits the longtime New Yorker against many in his home state, surprised King and others. But Trump advisers say his motivation to block money for the tunnel comes from several places.

Trump has complained about Schumer for months, saying the New York Democrat wants to resist his agenda for political purposes. Trump’s aides have occasionally gotten him “spun up,” in the words of one adviser, that Schumer is criticizing Trump privately, misrepresenting their conversations to the news media and blocking his agency nominees.

Trump has told others that Schumer would be less likely to provide votes for a larger infrastructure bill if he secures money for the tunnel now, two of these people said.

GOP officials on Capitol Hill say the White House also frequently complains about Frelinghuysen, who is pushing for the spending, for voting against the president’s tax bill.

“It’s a Schumer thing,” said one senior administration official.

There are also questions on how much Trump ever supported the project. For example at the Oval Office meeting, he said he would prefer to build runways over the tunnel because people could see them, people briefed on the meeting said.

Schumer decried Trump’s move. “This project is vital to fifty million people in the northeast corridor and to our American economy, and politics shouldn’t get in the way,” he wrote in a statement Saturday.

Trump’s aides, including budget director Mick Mulvaney and legislative affairs head Marc Short, have told the president the project is a financial boondoggle for the administration. It would make more sense, Trump’s aides have told him, to spend money on projects where he has broader political support and where elected officials are more likely to work with him.

If the project is going to be supported, it should be done as part of a larger infrastructure package where the states have to commit money, Trump’s aides have told him.

Several Trump aides said Saturday that while Trump was annoyed with Schumer, the decision was an administration position, not a personal pique — and there were valid policy reasons to oppose the spending.

“Mulvaney is the worst,” King said. “The president shouldn’t listen to him.”

A Mulvaney spokesman didn’t respond to a request for comment. A Schumer spokesman said the Trump administration’s infrastructure bill is already collapsing.

In New York, where Trump lost overwhelmingly, blocking the tunnel was yet another disappointment. Some hoped the president would bring his lifetime love for and knowledge about New York City into the Oval Office, even if the city largely disagreed with Trump on issues like immigration and abortion. They expected Trump to frequently return to his palatial penthouse inside Trump Tower, and officials, including New York City Mayor Bill de Blasio (D), lobbied the president.

At the beginning of the administration, West Wing officials from New York such as Gary Cohn, Jared Kushner, Ivanka Trump and Dina Powell, frequently hauled New York chief executives to the West Wing, where they sought ideas and gave elaborate presentations on the administration’s agenda.

That has all but stopped, officials say. New York business and elected officials lobbied hard against the tax bill — trying to fight a key state and local tax deduction that was taken away — and have been aggrieved by the president’s frequent cultural wars, his incendiary comments on race and his seeming willingness to not care about his home state. And Trump has rarely returned to New York.

“I don’t think there is a CEO who would not make the tunnel a top priority,” said Kathryn Wylde, who leads the influential big business group called the Partnership for New York City. “There’s not a chance given the president’s history in New York that he doesn’t understand that.”

Wylde said many remained upset about the tax bill, which passed last year.

King said there are many issues where Trump is doing a good job, like taking on the violent gang MS-13. The congressman said he also appreciated that Trump was forcing a gun debate with more moderate positions and that the economy had largely done well under the president.

But the president’s recently announced tariffs are likely to hurt New York, King said, and he doesn’t understand what he sees as a reversal from Trump on the tunnel.

“Whatever feud he has with Chuck, it’s on again, off again,” King said. “It’s not good for any of us. It’s bad enough he targeted his own state in the tax bill. Now he’s targeting his own state, his own region again.”

Mike DeBonis contributed to this report.