The House on Tuesday overwhelmingly passed a landmark housing bill, notching a rare bipartisan accomplishment ahead of the midterm elections and clearing the way for President Trump to sign the most significant piece of housing legislation in 36 years.

The bill’s passage, by a lopsided 358-to-32 vote, ended months of sparring between the House and the Senate over a sprawling measure that aims to tackle the housing crisis by boosting supply in a country facing an acute shortage of new homes. The Senate passed its version of the same bill Monday, by a vote of 85 to 5.

A White House official said Mr. Trump was expected to sign the bill into law on Wednesday. Passage of the legislation secured a much-needed achievement for his party months before midterm elections in which their congressional majorities are at stake. Voters have been particularly critical of the president’s handling of the economy, with only 33 percent approving of it, according to a New York Times/Siena poll last month.

The success of the bill, which almost collapsed several times amid Republican infighting over the past few months, reflected an appetite among lawmakers in both parties to address a crucial affordability issue months before they face voters.

With dozens of provisions, the 21st Century Road to Housing Act aims to touch communities across the country, addressing rural and urban needs as part of a strategy to eventually bring down housing costs. It loosens federal regulations, making it easier, faster and cheaper to build; eases lending rules; rewards communities that build; delivers aid to communities reeling from disasters; and, in a policy that proved to be one of the biggest flash points but was favored by Mr. Trump, sets new limits on the role institutional investors can play in the market.

“It is the most important and most comprehensive housing bill of this century,” said Shaun Donovan, president of Enterprise Community Partners and a former secretary of the Department of Housing and Urban Development in the Obama administration. “It contains dozens of provisions that, taken together, go directly at the most important housing challenge of this moment, which is our housing supply.”

Thank you for your patience while we verify access. If you are in Reader mode please exit and log into your Times account, or subscribe for all of The Times.

Thank you for your patience while we verify access.

Already a subscriber? Log in.

Want all of The Times? Subscribe.