This is what the most detested, divided, gridlocked Congress in recent memory looks like when it works.

At one point in the past two weeks, lawmakers fought over the definition of a catfish. They fought over the question of when life begins. They fought about health-care legislation that passed two years ago and an immigration bill that failed 17 months ago.

One day, Democrats staged a walkout of the House chamber. On another, a Republican held a committee hearing to study his committee hearings.

And then — on the last afternoon of the last workday — they managed to complete the work that had been hanging in the balance the whole time. They saved student borrowers and their parents from an increase in college-loan interest rates and saved states from running out of highway funding.

That was accomplished with the last-minute appearance of a 596-page bill that several lawmakers hinted they had not read.

“No wonder our approval rating is 10 percent. Nobody knows what we’re voting on,” Sen. Rand Paul (R-Ky.) said Friday afternoon as a few dozen somber tourists looked down from the Senate gallery.

The past two weeks represented a final chance for lawmakers to pass substantive legislation before the fall election, and a look inside the Capitol over the days before the Fourth of July recess reveals that this Congress, with its reputation for acrimony and gridlock, may be finally learning how to do its business.

But only after it has done everything else.

Week 1

Monday, June 18. Two weeks to go.

“They face difficult decisions and difficult times,” said House Chaplain Patrick Conroy .

He was praying mainly for legislators who weren’t there. Most wouldn’t return from their districts for hours, following a congressional tradition that the workweek starts around dinnertime on Monday.

These were difficult times, but familiar. Congress had tiptoed to the edge of disaster before — in spring of last year when the House’s deficit-averse GOP majority demanded substantial cuts to federal spending and almost forced a government shutdown to get them, and then again last summer when the United States faced a default on its loan obligations because Congress could not reach a deal on increasing the federal government’s borrowing limit.

But here they were again.

Failing to pass a student-loan bill would suddenly and sharply increase payments for about 7 million people. Failing to pass a highway bill could put many people — perhaps millions — out of work. Not the same as a national default or a government shutdown, but potentially catastrophic for the millions of Americans involved.

Both sides had delayed a solution by proposing options intended only to score political points.

Republicans wanted to pay for student loans by raiding a fund from President Obama’s health-care law. Democrats wanted to do it by cutting tax breaks for business executives making more than $250,000 per year.

“Lord,” Senate Chaplain Barry C. Black intoned in his own near-empty chamber that day, “lead them from the path of disunity.”

But seven days remained, and that left time for plenty of disunity.

“We’ve tried. We cannot get Republican votes. We’ve tried,” Senate Majority Leader Harry M. Reid (D-Nev.) said on the Senate floor after the chaplain had finished. Reid had begun the Senate’s business that day with a speech that veered sharply away from the Senate’s actual business.

Instead, he attacked Republicans for something they had done more than a year before, in late 2010. Back then, 36 Republicans and five Democrats blocked the “Dream Act,” which would have given some young illegal immigrants a path to legal status.

In his speech, Reid did not mention the five Democrats. Instead, he blamed Republicans and said the act’s failure may have pushed young people toward a life of crime.

“ ‘You can’t go to school,’ ” Reid said. He was now imagining himself talking to a young immigrant. “ ‘What you can do is go ahead and be part of a gang.’ ”

One explanation for the odd ways Congress works is that Congress does not know that Americans are probably not watching. Its members inhabit a busy mini-bubble within the larger Washington bubble, surrounded by attentive crowds of staffers, reporters and lobbyists. This allows for an inflated sense of their audience, which leads legislators to see every day as a chance to score points in the public eye.

That could mean forcing opponents to take an embarrassing vote. Or forcing them to squirm through a critical speech. But the political benefits of such maneuvers may be limited by the fact that few people actually see them happen.

Or you could hold an entire congressional hearing to prove you were right.

Rep. Peter T. King (R-N.Y.), the chairman of the House Homeland Security Committee, was unhappy that he had been criticized for previous hearings he conducted on the question of Muslim radicalism in the United States.

So King held another hearing, to ask witnesses what they had thought of the first ones.

“The committee is meeting today,” King said, in this moment of meta-legislating, “to hear testimony on the Muslim community’s response to this committee’s hearings.”

Across the Capitol that same week, two Senate Democrats had a brief debate about what is — and what is not — a catfish.

“It is disputed,” said Sen. Mark Pryor (D-Ark.), “about whether they meet the definition of catfish.” Pryor was trying to rebut an amendment supported by Sen. John F. Kerry (D-Mass.) that would end a program for the inspection of imported catfish-like fish. These Asian fish, Pryor said, “certainly aren’t an American variety of catfish.”

Kerry won. His amendment was adopted, and the Senate passed the farm bill 64 to 35. This was actual legislating, the renewal of a popular bill that pleased agricultural interests.

It is the kind of thing that used to be nothing special in the Senate. The kind of thing that — now — is rare and savored. In the news conference afterward, Sen. Pat Roberts (R-Kan.) seemed near tears.

“Maybe we’ve done something special here,” Roberts said, “and signaled to the American people that in the middle of a tough election year we can actually get something done.”

Then, at 5:40 p.m. Thursday, the Senate adjourned and went home for the weekend.

Week 2

Monday again. One week to go.

The Senate met for five hours, talking about a bill to renew the federal flood insurance program. But the most important words were spoken in private. Paul made it known that he would block that bill unless Senate leaders allowed a vote on one of his amendments.

That amendment, as it happened, was not about floods or insurance. Instead, Paul wanted to make other senators vote on when human life begins. His amendment declared that was “at the moment of fertilization [or] cloning.”

That vote might have forced some vulnerable Democrats to choose between pro-abortion-rights and antiabortion factions in their base. Reid pulled the legislation off the floor.

“With the end of the month staring us in the face,” Reid said, “we have so many important things we have to do.”

On Tuesday, the Senate did one of those things.

It passed, 92 to 4, a bill that renewed the Food and Drug Administration’s program for testing new medicines. The measure then went to the president for his signature.

“The Senate the last couple of months is operating like it used to,” Minority Leader Mitch McConnell (R-Ky.) said that day. “We’ve had amendments, we’ve had votes, we’ve passed bills. For some of our members it’s almost an out-of-body experience.”

If it was, it didn’t last. Thursday brought a high-volume return to this Congress’s bitter partisan divisions.

In the morning, the Supreme Court issued its decision upholding Obama’s health-care law. That set off a full day of speechifying about a bill from Congress’s past.

“Mr. Speaker, today is not a victory for one party or another,” said Rep. Carolyn B. Maloney (D-N.Y.), on a day when her party was celebrating a huge victory. “It is not a victory for an ideology. It is a victory for the American people.”

That afternoon, the House voted to find Attorney General Eric H. Holder Jr. in contempt of Congress. A total of 238 Republicans said Holder had not been forthcoming in a congressional inquiry into a federal gun-tracking operation called “Fast and Furious.” Seventeen Democrats agreed.

More than 100 other Democrats walked out, filing down the chamber’s center aisle. Many thought a “no” vote would not have sent a strong enough message.

At the end of that day, the deadlines were still there.

“I was scheduled to be in Lake Tahoe tomorrow, but I can’t be there,” Reid said in the Senate. “Other people have certainly more important trips than that.”

Finally: Friday. The two chambers faced what they had been putting off.

That turned out to be a mega-bill, worked out by House and Senate negotiators. It included new agreements on student loans and highway funding. And it included the flood insurance bill that Paul had stopped earlier in the week. And a measure to continue the cleanup of the BP oil spill in the Gulf of Mexico.

At almost 600 pages, it proposed to spend an estimated $95.9 billion of taxpayers’ money over the next five years.

“We’re rushing to the floor with vital legislation that most members have hardly had the chance to read,” Rep. Alcee L. Hastings (D-Fla.) said on the House floor Friday morning. “This . . . is the very embodiment of congressional dysfunction.”

Rep. Rob Woodall, a freshman Republican from Georgia, stood up to ask if his colleagues would like to take some extra time to study the measure.

“Would you rather rush [this] to the floor today and get home, for all the commitments you’ve made over the weekend?” he asked his colleagues. “Or would you rather stretch this thing out and get it right?”

Stretching it out lost.

A little before 1:30 p.m., they voted: 373 for, 52 against. All the “no” votes came from Republicans. Woodall was a “no,” Hastings a “yes.” In the plaza outside the House chamber, members walked out to waiting cars, weaving through the sweaty tourists into their weekends.

At the Senate end of the Capitol plaza, the cars were already gathering.

“I am overwhelmed by the amazing vote that we just had,” Sen. Barbara Boxer (D-Calif.) said after the bill passed 74 to 19. The deadline had been beaten, and the chamber was almost empty again. “It sends a tremendous signal to the people of America,” Boxer said. “And that is that we can work together. Do not give up hope.”

Rosalind S. Helderman and Ed O’Keefe contributed to this report.