NEW YORK - As the gulf oil spill gushed out of control last spring and summer, BP's financial liabilities seemed big enough to sink the company. No more.

Cleanup, government fines, lawsuits, legal fees, and damage claims will likely exceed the $40 billion that BP P.L.C. has publicly estimated, according to an Associated Press analysis. But they will be far below the highest estimates made over the summer by legal experts and prominent Wall Street banks, such as Goldman Sachs, which said costs could near $200 billion.

BP will survive the worst oil spill in U.S. history for several reasons:

It has little debt.

Its worldwide businesses are forecast to generate $26 billion next year in cash flow from operations.

The environmental impact of the spill appears to be not as bad as feared.

The U.S. government seems unlikely to ban BP from gulf drilling.

To bolster its finances, BP has cut its dividend, issued debt, and sold more than $21 billion in assets.

"It could have been a lot worse," said Tyler Priest, a University of Houston petroleum historian who serves on President Obama's spill investigation committee. "BP is going to come back from this."

Many influential investors appear to agree. According to Thomson Reuters, 23 large asset-management firms - including BlackRock Investment Management, Managed Account Advisors, and Rydex Security Global Investors - more than doubled their holdings of BP stock from July through September.

At Wednesday's closing of $43.95, BP's stock price had risen 63 percent from its low of $27.02 on June 25. It is still down 27 percent from its close of $60.48 on April 20, the day of the gulf oil explosion and spill. The well was capped July 15.

The AP analysis shows the company is likely to face $38 billion to $60 billion in spill-related costs. A settlement with the federal government could reduce that amount, but a successful class-action lawsuit could add billions more.

The analysis includes:

Paid so far. BP already has paid $10.7 billion to plug its well, clean up the spilled oil, and cover damage claims and other costs.

Claims fund. The company in August set up a $20 billion Gulf Coast Claims Facility fund for individuals and private businesses that were affected by the spill. So far, it has paid $2.7 billion to address nearly 168,000 claims. In all, nearly half a million individuals and businesses have filed claims.

Fines. The Justice Department is suing BP for violating the Clean Water Act. The government's estimate of 4.9 million barrels spilled means BP faces between $5.4 billion and $21.1 billion in fines. The government has a history of settling with companies for as little as 50 cents on the dollar to avoid lengthy disputes, said Eric Schaeffer, former head of the Environmental Protection Agency's enforcement division.

Legal fees. BP has hired lawyers, engineers, and geologists to defend the company. These experts could cost as much as $2 billion.

Lawsuits. The toughest costs to estimate are future settlements and judgments from the hundreds of lawsuits filed against BP, including any class actions. Shrimpers, oystermen, charter-boat operators, restaurant workers, and real estate developers are suing BP for lost business. Oil-rig workers and cleanup crews are making personal-injury claims. And gulf states and local governments are expected to sue for lost tax revenue and environmental damage.

However, BP may be able to spread the spill's costs around. Minority partners Anadarko Petroleum Corp. and MOEX 2007 L.L.C. own 35 percent of the well operation, and rig owner Transocean Ltd. also may be asked to pay.

Also, since the spill, BP has aggressively shored up its finances, such as by cutting the dividend and selling assets.