For House Speaker Nancy Pelosi, resisting President Trump’s demand for border wall funding during the longest government shutdown in history was more than a matter of strong disagreement with his immigration policies.

“We cannot have the president, every time he has an objection, to say, ‘I’ll shut down the government until you come to my way of thinking,’ ” Pelosi (D-Calif.) said. “If we hold the [federal] employees hostage now, they’re hostage forever.”

Pelosi has so far carried the day, with Trump backing down and agreeing to reopen the government through Feb. 15, pending negotiations on a permanent spending deal that were at an impasse on Sunday.

Whether she knew it or not, Pelosi was echoing arguments invoked during an even longer and more bitterly partisan funding battle 140 years ago, in which President Rutherford B. Hayes, a Republican, vetoed repeated attempts by Democrats in Congress to attach repeals of Reconstruction-era voting rights protections to government funding bills between April 1879 and June 1880.

Hayes let government funding lapse rather than cave on principle — at a time, to be sure, when the federal government was a comparatively tiny operation, with only seven Cabinet departments, total spending in the tens of millions of dollars and fewer than 40,000 men in uniform.

To have done otherwise, he wrote at the time, would have been to acquiesce in “unconstitutional and revolutionary” political methods.

Hayes’s ultimate victory in the struggle set precedents that help explain why government shutdowns were relatively rare until a new period of hyperpartisanship began in the 1990s.

An Ohio politician and Civil War general, Rutherford Birchard Hayes became president in March 1877, under a cloud because the results of the 1876 presidential election had been disputed, and he ended up winning only after months of partisan wrangling.

Notwithstanding his support for African American rights, and his political need to protect what were then the pro-Republican votes of blacks in the South, Hayes was eager to appease Southern Democrats for the sake of national stability after a decade and a half of war and Reconstruction.

So he withdrew U.S. Army troops from strategic positions in Louisiana and South Carolina, and signed an 1878 bill, backed by Southern Democrats, that limited the use of soldiers in state-level political disorders.

In 1879, however, a new Congress took office, dominated by Democratic majorities in both the House and Senate for the first time since the Civil War. Of the 192 Democratic senators and representatives, 129 were former soldiers in the Confederate Army.

Their goal was to recover in Congress some of what they had lost on the battlefield: to repeal the federal government’s postwar legal authority to protect African American voters in the South.

Knowing Hayes would never sign such measures as free-standing legislation, the Democrats attached them to must-pass appropriations bills.

The first of Hayes’s vetoes was his April 29, 1879, rejection of a funding bill for the U.S. Army itself, to which the Democrats had attached a rider forbidding the use of troops to guard polling places during federal elections. Without such protection, violent white-supremacist groups could intimidate African Americans with impunity.

In his veto message, Hayes, sounding very much like Pelosi, implied that the Democrats were taking the Army hostage.

“To say that a majority of either or both of the Houses of Congress may insist on the approval of a bill under the penalty of stopping all of the operations of the Government for want of the necessary supplies, is . . . a dangerous violation of the spirit and meaning of the Constitution,” Hayes wrote.

Hayes’s stand galvanized Republican partisans; GOP clubs in four Midwestern cities assembled and fired 38-gun salutes in his honor, writes a historian of the episode, Frank P. Vazzano. In Congress, Republican members also rallied to the president, and their votes denied Democrats the two-thirds majority needed to override the veto.

The Democrats’ attempt to defund the military to advance their own selfish racial and partisan agenda alienated public opinion. Recognizing that, Democrats allowed the Army appropriations to pass but then tried to attach similar voting-protection repeals to funding bills for the Justice Department and the U.S. marshals.

Hayes vetoed those, too, eventually forcing the Democrats to admit defeat and, in the election year of 1880, accede to full and nearly unconditional funding of the federal government.

The political damage to the Democrats from their display of extremism was so extensive that Republicans took back both the House and Senate in the 1880 election.

James A. Garfield, the Republican leader in the House who had orchestrated support for Hayes in that chamber, won the presidency.

It was surely the finest hour of Hayes’s one-term presidency. Whether it was, in fact, a contest over true constitutional principle, as he asserted, is not clear.

Congress was within its rights to pass whatever laws it wanted — and Hayes was within his rights to veto them, as he did. In fact, many policy-related riders have been attached to appropriations bills, both before and since the battle between Hayes and the ex-Confederate Democrats.

Today, Pelosi argues that it’s the president who’s attempting to rob Congress of its constitutional prerogatives — when, in fact, it might be more accurate to say that both she and Trump are exercising all the power the Constitution gives them.

The ultimate check on such behavior is the public’s judgment, both on the merits of each side’s policy goals and on the methods by which they pursued them.

Blame for shutting the government down was politically costly in Hayes’s time, and might be in 2019, too, though the definitive verdict, now as then, awaits the next presidential election.

Read more Retropolis: