The District government ended fiscal 2012 with a budget surplus of as much as $400 million due to stronger-than-expected revenue collections and a stable local economy, according to government officials with knowledge of the pending announcement.

The surplus is another sign that the District continues to emerge from the recession on a solid financial footing as new residents and businesses continue to flock to the city. The District finished fiscal 2011 with a $240 million budget surplus.

Officials spoke about the expected surplus, which Mayor Vincent C. Gray and Chief Financial Officer Natwar Gandhi plan to announce Tuesday, on the condition of anonymity because they are not authorized to speak about it publicly.

David Umansky, a spokesman for Gandhi, declined to comment. Umansky said officials are waiting for “final numbers from auditors.”

But news of the expected surplus is setting in motion an intense debate about how the excess funds should be spent.

Even before they knew the exact figure, liberal activists began lobbying council members this week to use some of the surplus to fund social and human service needs in a city where 30 percent of children live in poverty.

Gray (D) is expected to push to divert the bulk of the savings into the city’s coffers, trying to build up a two-month cash reserve that the city could fall back on in an emergency, officials said.

According to preliminary estimates, the surplus includes about $200 million in additional revenue collected last year, as well as about $100 million from under-spending by agencies, officials said.

In September, Gandhi said at least part of the surplus originated from a “windfall” in estate taxes, as well as higher-than-expected revenue from traffic tickets.

About $100 million was generated from dedicated fees that went unspent. That money can only be used for what it was designated for; excess funds from the city’s 5-cent bag tax, for instance, must be used on Anacostia River cleanup.

What to do with the remainder of the surplus could become a point of contention between Gray and the D.C. Council. When it approved this year’s budget, the council included a “wish list” of dozens of items that it would prioritize for spending if a surplus emerged.

The surplus is expected to buttress Gray’s claims that the District government remains well-managed, despite distractions from the federal investigation into the mayor’s 2010 campaign.

District officials also expect an upward revision in revenue in the current fiscal year.

“Our projections are showing the same trends and forces that drove unexpected revenues in ’12 are going to be in play in ’13,” said a senior Gray administration official. “With our projections, we can hold the line about being fiscally responsible now, and use new money in ’13 to make some new social investments.”

The city faced hundred-million-dollar shortfalls in fiscal 2009 and 2010, resulting in some tax increases and spending reductions. But the District largely escaped the tough decisions faced by other cities hit harder by the economic crisis.

Still, D.C. officials warn that the city needs to prepare for the possibility that the region’s economy could sputter if Congress and President Obama agree to deep cuts in federal spending.

The District is also nearing its debt cap, essentially making it more difficult to fund new capital projects without federal funding.