If the United States loses its top credit rating as a result of failing to raise the limit on federal borrowing, Maryland and Virginia could also be downgraded because their economies are so dependent on federal spending, Moody’s Investors Service said Tuesday.

A downgrade would make it harder and more expensive for Maryland, Virginia and three other states that received similar warnings to borrow money. This could prove especially problematic over the long term if the states have to borrow to fund retiree and health benefits.

The situation highlights how vulnerable the states’ economies are to a federal default. If the federal debt limit is not raised by Aug. 2, the U.S. government would not have enough money to pay all its obligations. As a result, payments to federal employees, retirees, service members and retirees could be pared dramatically. In addition, many government contracts could be suspended, potentially dealing a setback to hundreds of companies in the Washington region.

Virginia could be downgraded even though the state is required to maintain a balanced budget and managed to record a $311 million surplus in the fiscal year that ended in June. Maryland also must balance its budget and has made severe cuts in each of the past four years to meet that requirement.

Both states currently hold top-notch AAA ratings from the three major credit-rating companies.

“Through no fault of our own, we have a AAA bond rating since 1938 that we have been informed just hours ago may be in jeopardy and put on the watch list,” Virginia Gov. Robert F. McDonnell (R) said at a news conference in Richmond. “I’m very unhappy. In fact, we’re furious.”

A spokeswoman for Maryland Gov. Martin O’Malley (D), Raquel Guillory, cautioned against overreacting to the Moody’s announcement.

“Moody’s hasn’t done anything yet. It’s not surprising they would reevaluate considering we have a large number of federal employees and federal contractors. But we think that Maryland is better positioned than most to ride out whatever happens on the federal level,” she said.

In Maryland, the warning threatened to affect the interest rates that large institutional investors would offer next week in a scheduled sale of about $500 million in bonds for construction of schools, prisons and other public works. Technically, those bonds will retain a triple-A rating, but state fiscal experts said the outcome was unclear because at no time in recent memory has the state conducted a bond sale while under a credit watch.

Maryland’s plan to refinance as much an additional $200 million in debt next week could also be thrown into limbo, state fiscal experts said. Maryland has repeatedly used that tactic to reduce costs, borrowing new money at low rates and using it to retire old debt.

Like many other states, Maryland’s debt costs are trending toward 30-year highs, even without factoring in billions in unfunded retiree health-care and pension costs. But in Maryland, O’Malley and the state’s Democratic-controlled legislature have sought to use bonds and other borrowing to continue to fund programs that politicians in other states have gutted during the economic downturn.

Warren Deschenaux, the Maryland General Assembly’s chief budget analyst, said the full impact of any federal default would come into view after the state finishes calculating its year-end financial results, in about a month.

“We are already in territory that nobody would have imagined we would find ourselves in,” Deschenaux said. “Until the federal government knows what they’re doing and we find out about it, we won’ t know how to respond.”

Deschenaux added, “The only good news I can see is this should be over in a couple weeks.”

McDonnell said he plans to send a letter to federal officials Wednesday. He said he understands that Virginia is on the list because of the significant amount of money the state receives from the Defense Department and other federal sources.

McDonnell and state legislators visited all three ratings agencies in New York last year, including Moody’s. “Moody’s could not have been any more complimentary about the way we are doing things in Virginia,’’ McDonnell said.

Virginia has $7 billion in debt for big-ticket projects in mental health, parks and higher education, or $895 for every Virginian.

The three other states warned of a potential downgrade are New Mexico, South Carolina and Tennessee — largely because of their reliance on bonds whose rates could spike with a federal downgrade.

“While all states are indirectly linked to the U.S. government to some degree, we have identified the five AAA-rated states that are most vulnerable to changes in the U.S. government rating,” said Nicholas Samuels, a vice president in the Moody’s state ratings team.

Moody’s stressed that a downgrade of the United States would not necessarily prompt a downgrade of the states.