The cost-cutting and improved loan quality helped the nation's biggest U.S. mortgage lender overcome meager revenue growth.
Net income rose to $5.27 billion from $4.40 billion a year earlier, excluding dividend payments on preferred stock. On a per-share basis, earnings were 98 cents, beating the 93 cents forecast by Wall Street.
Revenue edged up to $21.4 billion from $21.3 billion and exceeded Wall Street expectations.
The company's stock rose 74 cents, or 1.8 percent, to $42.63 in trading Friday.
Interest rates on mortgages have risen sharply in recent weeks, and analysts are concerned about the potential impact on its mortgage business.
The San Francisco-based bank controls nearly a third of the U.S. mortgage market, and that has helped bolster its earnings recently. Much of its lending came from refinancing, which has been reduced by the spike in interest rates.
Wells Fargo funded $112 billion worth of mortgages, down from $131 billion in the second quarter of 2012.
That's likely to decline to $100 billion or lower in the third quarter, said Chief Financial Officer Tim Sloan.
Still, as refinancing activity is waning, the overall improvement in the housing market is lifting business in new mortgage loans, Sloan said in a telephone interview.
Though Wells Fargo is the largest mortgage lender, it's important to keep perspective on that business's contribution overall, he said.
"It's not as if it's 50 percent of our earnings," Sloan said.
The bank's strong showing for the quarter "wasn't really about any one business," he said.
Wells Fargo reduced expenses to about $12.2 billion, down $142 million from a year earlier. The savings were mainly due to lower employee benefits.
Fewer bad loans cut Wells Fargo's credit losses nearly in half to $1.2 billion. The allowance for credit losses fell to $16.6 billion as of June 30 from $17.2 billion as of March 31.
"Wells Fargo again demonstrated an ability to grow during a dynamic economic and interest-rate environment," the bank's chairman and CEO, John Stumpf, said in a statement.
Mortgage rates jumped late last month from near-record lows and added thousands of dollars to the cost of buying a home, after the Federal Reserve signaled that it could slow its bond purchases later this year. The average rate on a 30-year fixed mortgage rose this week to 4.51 percent, the highest in two years.
In the short run, higher rates appear to be drawing potential home buyers off the sidelines. Buyers want to get a mortgage before rates rise further from their historically low levels. In the long run, more expensive home loans might slow the housing market's recovery, which has helped drive the U.S. economy.
At the same time, higher loan rates would allow banks to make more from mortgage lending.
Wells Fargo, the fourth-largest U.S. bank by assets, was little known outside the Western U.S. before scooping up a teetering Wachovia in the depths of the financial crisis in 2008. The bank has turned a profit every quarter since 2009, the year it wrapped up its acquisition of Wachovia.
Wells Fargo's competitor in mortgage lending, No. 1 U.S. bank JPMorgan Chase, also reported a surge in second-quarter profits Friday and said it reduced its provision for loan losses in its consumer banking division by $1.5 billion as the number of customers failing to repay their loans remained low.
JPMorgan earned $6.1 billion in the period, up 32 percent from a year earlier.