By Liz Hoffman

Morgan Stanley's second-quarter earnings rose 45% as the coronavirus ripped through the U.S. economy and financial markets.

The bank reported revenue of $13.4 billion and profit of $3.2 billion, or $1.96 per share, on Thursday. Both were quarterly records for the firm and well above the expectations of Wall Street analysts, who had predicted profit of $1.77 billion, or $1.12 per share.

Morgan Stanley and Bank of America Corp. were the last of the big U.S. banks to report financial results for a period that posed the biggest test of the financial system since 2008. Results shook out along recognizable lines: Big commercial and consumer lenders like JPMorgan Chase & Co. and Bank of America took provisions for loan losses that dragged down earnings, while a surge in securities trading and underwriting favored Wall Street-heavier firms such as Morgan Stanley and Goldman Sachs Group Inc.

That flips a script that dictated bank profits for a decade. The long recovery from 2008 favored big Main Street lenders closely tied to the U.S. consumer, who borrowed and spent heavily during a period of rising employment and steady economic growth. That same calm, sunny outlook sapped markets of the kind of volatility that keeps trading desks busy.

The pandemic brought "all sorts of massive uncertainty," said Chief Executive James Gorman, who himself contracted Covid-19 earlier this year. "Some of that uncertainty, as we just demonstrated, played to our favor."

Morgan Stanley's wealth-management brokerage, the country's largest, brought in $4.7 billion in revenue during the second quarter. Mr. Gorman often calls the unit, which clips fees managing nearly $2.7 trillion of clients' money, a ballast that steadies the firm while its Wall Street businesses of deals and trades provide the power.

That engine purred in the second quarter. Morgan Stanley's trading revenue rose 68% from the same period a year ago to $5.6 billion, its highest in a decade. Chief Financial Officer Jonathan Pruzan said in an interview that average client balances in the firm's trading arm were 15% lower in the second quarter than in the first and that computer-driven "quant" funds, for which Morgan Stanley is the leading broker on Wall Street, were slower to return to the market.

The firm's investment bankers generated $1.6 billion in revenue helping companies sell stock and debt to the public, two-thirds higher than a year ago. Corporate bond issuance hit a year-to-date record of more than $1 trillion by the end of May, showering fees on bankers who placed that debt with investors. The surge also helped banks in another way, by giving companies the cash to repay bank credit lines they drew on in the early days of the pandemic -- loans banks nervously funded, hoping they would be paid back quickly.

Mr. Pruzan said the firm had "consciously avoided consumer credit" as well as commercial banking, which means it is less exposed to a wave of defaults that looks increasingly likely as much of the U.S. economy remains shut down. Its loans to companies and trading clients are mostly highly rated and backed by assets such as real estate and securities portfolios, he said.

The bank's return on equity, a measure of how profitably it invests shareholders' money, rose to 15.7%, above the high end of a target range set last year by Mr. Gorman. Morgan Stanley also remains comfortably above a minimum capital level it will have to hit starting this fall.

Like other big banks, Morgan Stanley is temporarily barred from buying back shares or significantly increasing its dividend, which the Federal Reserve hopes will help preserve cash for banks to weather the downturn. But Mr. Gorman said he was eager to "get back on the buyback train" given the cushion his firm has over minimum requirements.

"We don't want to sit on this capital," Mr. Gorman said. "We want to put it to work."

He said Morgan Stanley remains on track to complete its pending acquisition of E*Trade Financial Corp. late this year. The deal, struck just before the pandemic hit and valued at the time at $13 billion, is meant to bring in new clients to the firm's wealth arm, upgrade Morgan Stanley's technology, and introduce the blue-blooded firm to a younger generation of investors.

Though it is known for its dot-com vibe and quirky television ads, E*Trade's crown jewel is a lower-key business: managing the stock that employees at hundreds of companies receive as part of their pay. Those shares are typically locked up for a few years and when they become available, Morgan Stanley aims to move those employees into brokerage accounts. It also has international ambitions for the U.S.-centric E*Trade.

The deal will also bring some $38 billion in deposits. Morgan Stanley, which doesn't have branches or traditional bank accounts, has been trying to grow deposits as a low-cost source of funding. That is more crucial than ever as the pandemic -- and the recession that is likely to stretch on -- puts stress on banks' finances.

In the meantime, costs to integrate E*Trade shaved about 1 percentage point off the profit margin in Morgan Stanley's retail brokerage, which slipped below the 28% level Mr. Gorman has been targeting.

Write to Liz Hoffman at liz.hoffman@wsj.com