Bank of America, the largest retail bank in the US, agreed last night to buy troubled stockbroker Merrill Lynch for around $50bn (£27.8bn) in a deal that traders said could resolve the firm's funding crisis.

However, sceptics said the deal may prove disastrous for Bank of America, which continues to wrestle with its own losses from the US sub-prime housing disaster.

Merrill Lynch is the world's largest and most widely recognised stockbroker. Its dominance of retail stockbroking, with an army of 16,000 brokers around the world, and independent spirit on Wall Street earned it the moniker the Thundering Herd. It has also bolted on businesses, such as its hedge fund BlackRock, that are known to have proved enticing to Bank of America.

A combination of the two will create a global financial services giant involved in everything from fixed-income trading to stock underwriting to credit card lending, which will rival Citigroup, the biggest US bank in terms of assets.

Most industry analysts said the merger represented a good fit, with few overlaps between the two institutions. If the deal goes according to plan, Bank of America will be able to offer Merrill's retail stockbroking services to its huge customer base. Bank of America does have an investment bank already, but it has never been terribly strong.

Where there is duplication, however, the combination of the two companies could result in more layoffs. Both Merrill and Bank of America have already cut thousands of investment banking jobs over the past year.

In April Merrill Lynch announced 4,000 jobs cuts - one in 10 of its workforce - after it reported that its losses from the sub-prime lending crisis had reached $24bn.

Bank of America, like most banks in the US and Europe has been accused of burying its head in the sand while its losses have mounted day by day. It also bet on an early end to the credit crunch with its $4bn purchase of Countrywide, one the of the largest lenders in the US and a victim of the collapse in property values in the boom states of California, Florida and the eastern seaboard.

Some analysts said it overpaid for Countrywide and was making the same mistake again with Merrill Lynch

They said the deal differs from JPMorgan Chase's buyout in March of Bear Stearns in that the ailing Bear Stearns was sold at a steep discount and with financial backing from the Fed.

The Fed has ruled any further support for Wall Street's banks, telling them they must resolve the crisis using shareholder funds rather than relying on taxpayers.

Merrill Lynch was a latecomer to the property boom and backed thousands of mortgages for homes bought at the top of the market. It also invested heavily in toxic mortgage backed securities that have been the downfall of all banks. But its financial position is stronger than the dire situation at Bear Stearns.

Richard Bove an analyst at brokers Ladenburg Thalmann, said: "For BofA to step in and offer a premium strikes me as being imprudent. BofA could get a much better deal if they just sat and waited."

Merrill Lynch, whose current CEO is John Thain, striven to end its funding crisis in earnest since July when it sold its stake in financial news and data provider Bloomberg for $4.43bn, and then sold a huge chunk of its toxic asset-backed securities and issued new stock to raise another $8.5bn.

Merrill Lynch, founded in 1914, was the nation's largest workforce of brokers and its name is known in towns across America. It made its reputation investing the funds of millions of Americans, but in recent times has invested its own money, in particular in risky property assets.

Knowing that investors were worried about Merrill, John A. Thain, its chief executive and an alumnus of Goldman Sachs and the New York Stock Exchange, and Kenneth D. Lewis, Bank of America's chief executive, began negotiations. A source briefed on the negotiations said Bank of America had approached Merrill earlier in the summer but Thain had rebuffed the offer. Now, prompted by the reality that a Lehman bankruptcy would ripple through Wall Street and further cripple Merrill Lynch, the two parties proceeded with discussions.

On Sunday morning, Thain and Lewis cemented the deal. It could not be determined if Thain would play a role in the new company, but two people briefed on the negotiations said they did not expect him to stay. Merrill's "thundering herd" of 16,000 brokers will be combined with Bank of America's smaller group of wealth advisers and called Merrill Lynch Wealth Management.

Bank of America's roots go back to the Massachusetts Bank in the late 1700s, but it was better known as a west coast bank, having also evolved from the Bank of Italy, founded in San Francisco in 1904 by A.P. Giannini. A series of acquisitions including New England's Fleet Bank and then Bank of America's purchase by North-Carolina based NationsBank turned it into a bank with a more national presence. Although the combined company's headquarters moved to Charlotte, it retained the famed Bank of America name.