WASHINGTON — It was an unsightly and painful yearlong slog, but Republicans are finally getting what they so desperately craved — a major legislative victory in the form of a consequential tax overhaul.

By coupling a substantial corporate tax cut with an assortment of naked appeals to undecided lawmakers, Republican leaders pushed their tax bill through the House on Tuesday and the Senate on Wednesday, touching off a self-congratulatory tidal wave by a party that had struggled mightily through nearly all of 2017.

After an embarrassing inability to repeal the Affordable Care Act — a core promise by congressional Republicans since 2010 — Republicans knew they had no choice but to deliver a tax package or face brutal repudiation by their voters and campaign donors.

“Our attitude from the beginning was failure was not an option,” said Representative Steve Scalise of Louisiana, the No.3 House Republican and the party’s chief vote counter.