Maryland is ending the fiscal year with a $2.5 billion balance in its state budget, largely attributable to a windfall in tax revenue, state analysts said Thursday.

The rosy financial picture, which cuts a steep contrast to the state’s doomsday predictions in the spring of 2020, is a “direct reflection” of the federal government’s stimulus funding, officials said, and suggests that Maryland not only can avert budget cuts but expand investment in critical social services and supports that have buoyed the needy during the pandemic.

“The stimulus payments, both at the federal and state level, I want to emphasize, did exactly what they were supposed to do,” Comptroller Peter Franchot (D) said in a meeting with the state’s fiscal leaders. “They stimulated spending.”

While the revenue gains spell good news for Maryland’s economic recovery, Franchot warned that gaping income disparities persist across the state.

“Right now, two-thirds of the state’s population is doing just fine, and one-third is suffering mightily,” he said. “We still have a tale of two Marylands.”

Franchot urged state leaders to put a bulk of the budget surplus into the state’s rainy day fund and disburse the rest to families still reeling from the economic effects of the pandemic, including renters facing eviction and parents struggling to afford child care.

“The state’s surplus is a once-in-a-generation opportunity to invest in programs that lift all Marylanders and help stabilize housing and other critical expenses for our lower- and middle-income families,” Franchot said. “We must deliver this money quickly to those who need it most.”

On the basis of the budget surplus, Maryland’s Board of Revenue Estimates on Thursday added about $1 billion — nearly 2 percent of the state’s operating budget — to its revenue forecast for the coming year.

“Maryland is experiencing one of the strongest health and economic recoveries in the nation,” Gov. Larry Hogan (R) said in a statement.

With the help of the federal government’s stimulus packages, D.C., Maryland and Virginia have largely avoided the budget crisis predicted in the early months of the pandemic. Virginia ended its fiscal year with a $2.6 billion surplus, and D.C. was expected to close its books with at least $500 million of extra revenue.

Maryland in April passed a record $52.4 billion budget that sent cash payments to the poor, and gave bonuses to state workers and tax breaks to small businesses.

State analysts say the recent financial bump has been driven in large part by gains in tax revenue. Even in a year when 14 percent of employed residents lost their jobs and unemployment claims flooded the state’s system, personal income tax and sales tax revenue increased 9 percent and 7 percent, respectively. Wealthier taxpayers experienced “robust growth” in their capital income — in line with general gains in the U.S. stock market — and wage growth broadly exceeded expectations in the first six months of 2021, analysts said.

Corporate tax revenue jumped 39 percent, suggesting that larger firms were able to benefit during the pandemic by capturing additional market share left by smaller competitors or by taking advantage of the federal stimulus, Franchot’s office reported.

The increased spending is likely to continue in the near future, said Maryland Bureau of Revenue Estimates Director Andrew Schaufele. A sizable amount of stimulus money remains in Marylanders’ checking accounts, and that will help to drive the economy in the coming months as commercial activity continues on a bumpy road toward normalcy.

The recovery is subject, however, to some major uncertainties, Schaufele said. Chief among them is the potential impact of increased federal debt and the continuing coronavirus pandemic, including the threat of new variants.