By Richard Cowan and David Lawder

WASHINGTON (Reuters) - Congress narrowly averted a partial shutdown of the U.S. domestic security agency late on Friday night, but the forces behind the chaotic episode remain - fractious Republicans and House Speaker John Boehner's lack of control over them.

That may portend more serious trouble ahead as Washington confronts fiscal challenges on a grander scale. In five to seven months, the federal debt ceiling will again be reached, and by October Congress must pass spending bills to keep the government running in the new fiscal year.

Failing to deal effectively with these issues could have much more damaging repercussions - such as a broad government shutdown or a debt default - than a partial shutdown of the Department of Homeland Security (DHS).

What happens between now and then, including the handling of a one-week extension of Homeland Security funding, will be crucial. Some conservatives speak of ousting Boehner, but it is unlikely they can muster enough votes, while others made clear on Friday that they were willing to take big risks to score ideological points.

    Brinkmanship like this, reminiscent of 2013's 16-day federal government shutdown, was supposed to be over. Republican Senate Leader Mitch McConnell said there would be no more shutdowns after his party won control of the upper chamber and strengthened its grip on the House last November.

    Proclamations about Republicans showing they could govern soothed financial markets, which were rattled by the 2013 shutdown and badly shaken by 2011 budget fights that nearly resulted in an historic government default on its debt.

But Friday's confused late-night scramble renewed old concerns about dysfunctional government. The House rejected a three-week funding extension for the agency when conservatives rebelled because the bill did not block Obama's executive orders on immigration. On a second try late in the evening, House Democrats provided the votes to pass a one-week extension.

The angry conservatives' embarrassing rebuke to Boehner showed they are more fiercely determined than ever to rein in federal spending, shrink the government and challenge Democratic President Barack Obama on multiple fronts.

    "It’s very possible that come September, you could face this again," said conservative Republican Representative Joe Pitts of Pennsylvania, when asked about debt and budget fights ahead.

For small-government Tea Party activists looking to flex their muscles after November's election victory, any attempt to borrow beyond the $18 trillion national debt will be a red flag. Congress also faces a Sept. 30 deadline for passing spending bills that are certain to add to the $18 trillion debt.

    Unlike the upcoming debt limit and budget issues, the DHS battle was not about government spending, but about Obama's recent executive actions to suspend the threat of deportation for 4.7 million illegal immigrants.

Still, Trent Lott, a former Senate Republican leader, said some congressional Republicans will not be able to resist further confrontations, especially over spending bills.

    "I must say, there are going to be battles for the next two years trying to rein in Obama’s excesses with executive power and regulations," Lott said.

More executive actions are expected from Obama in environmental and other controversial areas. That could mean that clashes will intensify, with many conservatives still seeing spending power as their strongest leverage.

    Some of them say pressing the immigration fight is part of a non-negotiable duty for Congress to defend the Constitution. They say Obama took steps to change immigration policy that only Congress has the authority to carry out.

"This is not about immigration. This is about whether or not the president has the ability to unilaterally run this country, Representative Austin Scott of Georgia said in House floor debate on Friday.

The Obama administration counters that its unilateral action on immigration, after years of watching House Republicans block legislation, and has many presidential precedents.

Many Republicans are concerned that such fights are an election liability and undermine the party's ability to demonstrate it can govern responsibly. However, similar concerns have been aired with each successive battle.

    Republican Senator Mark Kirk, who could face a tough re-election in 2016, told Reuters that his party needs to change.

Referring to the DHS fight, the Illinois senator said: "I would say that this battle should be the end of the strategy of attaching whatever you’re upset at the president about to a vital piece of government."

(Editing by Stuart Grudgings and Kevin Drawbaugh)