WASHINGTON — A Democratic protest demanding votes on gun-control legislation led to pandemonium in the House chamber that did not end until early Thursday, when Speaker Paul D. Ryan and his fellow Republicans reclaimed control long enough to force through a major spending bill. They then abruptly adjourned and left the Capitol.

Furious Democrats remained on the House floor, where they huddled around their leader, Representative Nancy Pelosi of California, who praised their stand as a “discussion heard around the world.”

Ms. Pelosi expressed bewilderment at the Republican position. “What could they be thinking?” she asked. “Whatever it is, they don’t want to tell anybody about it. That’s why they left in the dead of night.”

The standoff, which began with a Democratic sit-in on the House floor just before noon on Wednesday, did not end until about 3 a.m. Thursday when Mr. Ryan — barreling over Democrats’ objections — took the rare and provocative step of calling a vote on a major appropriations bill in the wee hours and without any debate. He then adjourned the House, with no legislative votes scheduled until July 5.