Maryland finished the fiscal year in June with a $1 billion surplus as a strong economy and rising tax revenue helped erase a gaping shortfall the state faced as recently as two years ago, state officials announced yesterday.

Gov. Robert L. Ehrlich Jr. (R), who came to office in 2003 confronting a nearly $1 billion budget gap, hailed the surplus as "a remarkable turnaround" that he said vindicated his administration's spending cuts and resistance to some tax increases. He pledged to use part of the excess cash for tax relief but offered no details.

Across the nation, a revived economy has helped at least 34 states improve their revenue outlook this year. Virginia is expecting revenue to top projections by more than half a billion dollars for the fiscal year that ended June 30, and the District has accumulated cash reserves of more than $1.2 billion, in large part because of a real estate boom, officials said.

In Maryland, the budget turnaround could figure prominently in next year's election debate, with Ehrlich claiming credit for the rosier outlook and Democrats highlighting both the cost of getting there and the work that remains to close a chronic gap between spending and revenue.

"It's like deja vu, like watching George Bush under the 'Mission Accomplished' sign," said Del. Richard S. Madaleno Jr. (D-Montgomery), a member of the House Appropriations Committee, referring to the president's May 2003 declaration that major combat operations had ended in Iraq. "It's a little premature to declare victory."

Ehrlich, the state's first Republican governor in a generation, ran three years ago on a platform of fiscal restraint, accusing then-Gov. Parris N. Glendening (D) of squandering the state's last surplus.

Yesterday, in a carefully worded statement, Ehrlich said his administration was "able to turn things around for the better without raising the sales or income tax."

He made no mention of the state property tax, which the governor and lawmakers agreed to raise by nearly 5 cents on every $100 in assessed value in 2003. The governor also supported several other tax and fee increases that are generating more than $500 million a year in additional revenue for the state, according to legislative analysts. About $350 million of that flows into the state's $11 billion general fund, analysts say.

While Ehrlich touted his efforts to rein in spending in an overall budget topping $25 billion, Democrats pointed yesterday to double-digit increases in college tuition and cuts in a variety of programs, including open-space purchases, cancer research and health care for legal immigrants.

"I don't know how much credit the governor wants to take, given what he's done to our citizens over the past few years," said Sen. Ulysses Currie (D-Prince George's), chairman of the Senate Budget and Taxation Committee.

House Minority Whip Anthony J. O'Donnell (R-Calvert) said Democratic criticism of Ehrlich was disingenuous, given that House leaders last year backed an unsuccessful attempt to pass a $1 billion package of tax increases -- coupled with a property tax reduction -- that O'Donnell said was misguided. "Governor Ehrlich's response has been very prudent," O'Donnell said.

Assessments differed yesterday on how the surplus would affect efforts to legalize slot machine gambling, which Ehrlich and some lawmakers had offered as a partial solution to the state's long-term fiscal woes. Some Democrats suggested that interest would wane, though Ehrlich said he does not see the two issues as directly connected.

The governor also sought to contrast Maryland's situation with that of Virginia yesterday, saying during a interview on WBAL radio in Baltimore: "They have a huge surplus because they passed taxes when they didn't need to, when some fiscal responsibility was the thing to do."

A spokeswoman for Virginia Gov. Mark R. Warner (D) took exception to Ehrlich's comments.

"Let's be clear: Virginia lowered its food tax and income tax last year after cutting the size and cost of state government," said Ellen Qualls, Warner's director of communications. She added that Maryland had higher cigarette, gas and income taxes.

"Even after raising our sales and cigarette tax slightly, we're lower than Maryland in overall tax burden," she said.

Cecilia Januszkiewicz, Ehrlich's budget secretary, acknowledged that Maryland's strong economy was partly responsible for the revenue gains, but she said Ehrlich deserved credit for improving the state's business climate. Ehrlich also said President Bush's tax cuts helped fuel the state's economic growth.

A memo sent this week to Maryland lawmakers by the legislature's chief fiscal analyst cited "continued strong growth" in corporate taxes as one factor bolstering the surplus. The state's recent decision to close a tax loophole for Delaware holding companies "is probably a major reason for the big jump," said the memo, written by Warren G. Deschenaux, director of the Office of Policy Analysis.

In an interview, Deschenaux said the state has also benefited from collections related to a real estate market "going wild" and a surprising jump in capital gains taxes.

Legislative analysts project that the state could have another $1 billion shortfall by 2008, given continued funding of a major education initiative and escalating Medicaid costs.

Januszkiewicz also said that longer-term challenges remain but that the surplus should provide "a bit of breathing room" in addressing them.

"I think we still have issues, but there's certainly a cause for celebration," she said.

Nationally, a majority of states are experiencing a similar increase in revenue, with "an improving U.S. economy lifting all boats," said Arturo Perez, an analyst for the National Conference of State Legislatures. Thirty-four states had revised their revenue projections upward as of April, the last time the organization surveyed budget outlooks, largely on the basis of strong income and sales tax collections.

Staff writer Chris L. Jenkins contributed to this report.