Wells Fargo & Co.'s sizzling mortgage machine is starting to cool.

The nation's top mortgage lender said Friday that its revenue slipped in the first quarter for the first time in more than two years, largely because fewer people are taking advantage of ultralow interest rates and government programs to refinance.

Everyone had expected the refinance boom to slow, but bank executives were bullish that the revival in the nation's housing market would drive demand for new mortgages to buy homes, muting the refi slowdown.

"If anything today, there's probably a shortage of housing on the market," CEO John Stumpf told analysts Friday. "The amount of supply, especially in the lower end or starter houses … there's not a lot of supply out there."

"Americans have not lost their emotional attachment to homeownership."

Despite the dip in revenue, profits soared for the bank, which employs 20,000 people in Minnesota.

The San Francisco-based lender earned a record $5.2 billion, or 92 cents per share, in the first quarter, up 22 percent from the same time last year and beating Wall Street estimates.

A 5 percent drop in expenses helped drive the gains, along with setting aside less to cover souring loans.

Revenue, however, slid, and overall loan growth remains tepid. Amid an overall pullback in bank stocks Friday, Wells Fargo shares closed at $37.21, down 0.8 percent.

Joe Morford, a banking analyst at RBC Capital Markets, has the bank rated at "outperform" and said he thinks the bank's overall story for investors remain strong.

"It's still a high-quality company delivering superior returns that's trading at less than 10 times earnings, and has 3.2 percent dividend yield."

One half of the bank's business, net interest income on loans, was down about 3.5 percent year-over-year on a tax equivalent basis.

The other half of the bank's business, noninterest income from ­myriad fees and charges on such things as deposits, credit cards and brokerage services, was down about 1 percent from a year ago and down from the previous quarter too. Lower mortgage banking revenue was a key culprit.

After four straight quarters of double-digit growth as people raced to take advantage of super-low interest rates and government programs to aid home refinancing, the bank's mortgage banking revenue appears to have peaked. It shrank by about 3 percent year-over-year in the first quarter.

The Home Affordable Refinance Program (HARP) was recently extended for two more years through the end of 2015, but bank executives said they don't expect it to generate a new wave of refinance activity.

HARP refinancings were about 10 percent of Wells Fargo's refinance activity in the first quarter, they said, down from the midteens last year.

Wells Fargo's net interest margin, or the difference between what it earns on assets and what it pays out in interest, continues to compress and dropped another eight hundredths of a percent to 3.48 percent.

Stumpf, head of the country's fourth-largest commercial bank, also took a moment in talking with analysts to address the ongoing "too big too fail" discussions.

"We need banks of all shapes and sizes to serve the diverse needs of a diverse economy," he said.

Jennifer Bjorhus • 612-673-4683