The prolonged negotiations among four senators that produced this week’s compromise on a modest gun control bill show how hard it is to reach bipartisan agreement on contentious issues in a time of sharply partisan politics.

So does last week’s apparent collapse of talks to craft a new COVID relief bill.

After all, it took months for another group of lawmakers to reach an accord on an infrastructure bill last year that promised tangible results for virtually every congressional district in the country.

To succeed in this environment takes strong leadership – as Texas Republican Sen. John Cornyn and Connecticut Democratic Sen. Chris Murphy showed in responding to the public’s demand to “do something” about the mounting toll of gun-related deaths.

But it also takes modest goals, and, even then, bipartisan efforts don’t always succeed. Another seemingly sensible new bipartisan agreement — curbing insulin costs — faces an uncertain future.

The reasons lie in a political climate, where neither party trusts the other, and in the numbers – incredibly close divisions in both houses, internal splits within each party, and the virtual disappearance of centrist lawmakers from both parties.

An array of analyses shows the most liberal Republicans — Sen. Susan Collins of Maine and Rep. Brian Fitzpatrick of Pennsylvania – have less liberal voting records than the most conservative Democrats – Sen. Joe Manchin of West Virginia and Rep. Jared Golden of Maine.

Still, small groups of more moderate lawmakers in both parties and both houses have worked across party lines seeking compromise solutions. More extreme members on the GOP’s right and the Democrats’ left often seek to foil such efforts.

In the middle is President Joe Biden, eager for some bipartisan accords and personally closer to his party’s more moderate center but often facing pressure from its left.

Those pressures sometimes succeed. One reason Biden rebuffed GOP efforts to compromise his initial $1.9 trillion COVID relief bill at the outset of his presidency was that party pressure was too strong to accept a smaller package.

Besides, the White House saw passing the larger bill as a no-lose political success that would set the tone for his presidency. (That it may have contributed to subsequent inflationary pressures shows victory sometimes has costs.)

There were similar pressures on the infrastructure bill, which Congress passed and Biden signed last August. But the appeal of the long-promised legislation overrode resistance on the flanks of the two parties.

Still, their concerns were evident when Congress passed the measure crafted by 10 Democratic senators and 10 Republicans. All but 13 House Republicans and most Senate Republicans voted against it, as did six of the most liberal House Democrats, members of the “Squad.”

In the Senate, however, all 50 Democrats were joined by a surprisingly large number of 19 Republicans in supporting it.

Now, with the approach of the midterm elections in which Republicans are favored to win the House and possibly the Senate, suspicions and acrimony between the two parties are evident.

Earlier this year, House Democrats forced removal from a major government funding bill of $15 billion for additional COVID relief, because it would have required states and localities to take the funds from prior assistance. Ever since, bipartisan talks have sought an alternative of $10 billion.

But those talks hit an impasse last week after the administration said it was shifting $10 billion from virus testing and protective gear to use for antiviral drugs and vaccines. Utah Republican Sen. Mitt Romney, the lead GOP negotiator, charged the administration had misled Congress on its need for additional funds.

Meanwhile, it took the four senators crafting the gun-related package 10 days to put their initial agreement into actual legislation. But on Tuesday, they announced success on the first such measure in years.

It includes an additional $15 billion for school safety and mental health programs and to fund “red flag” laws to keep deadly weapons away from dangerous individuals; provides enhanced review procedures for gun buyers under 21; penalizes so-called “straw” purchasing; clarifies who needs to register as a federal firearms dealer; and closes the so-called “boyfriend loophole,” affecting whether unmarried partners found guilty of violence against dating partners could own or buy guns.

Public opinion clearly played a major role. Cornyn said Texans are “disgusted and outraged” by last month’s murder of 19 children and two teachers in a Uvalde school, and “want Congress to take appropriate action to prevent the loss of more innocent lives.” But the Texas Republican got a taste of the potential political risks he faces from continuing conservative opposition to any gun control measures.

At last week’s Senate GOP lunch, he encountered sharp criticism from more conservative colleagues of the party whose leadership he may seek one day. And over the weekend, he was booed at the Texas state Republican convention when he defended his effort by stressing his success in blocking the stricter proposals of gun control advocates.

That could presage a conservative challenge when he faces re-election. But that’s four years away.

Some Democratic supporters of the more extensive gun measures that the House passed last week have expressed reluctance to settle for the more modest Senate package.

Still, Senate passage was assured when Republican Leader Mitch McConnell joined the prior 10 GOP supporters in backing the compromise bill. House concurrence is also likely, showing that, even in this partisan age, some bipartisan efforts can succeed.

Carl P. Leubsdorf is the former Washington bureau chief of the Dallas Morning News. Readers may write to him via email at carl.p.leubsdorf@gmail.com.