The nation’s largest banks made a killing in the mortgage business last year.

Earnings released in the past several days show mortgage activity accounting for about 15 percent of the profits at Wells Fargo. JPMorgan Chase, meanwhile, reported $418 million in profit from its mortgage banking business, compared with a loss of $269 million a year earlier. Even Bank of America, which has been retreating from the mortgage market, posted a 41 percent spike in loan originations in the fourth quarter, to $22 billion.

But these robust gains may not last once the refinancing boom peters out and the government’s slew of new mortgage rules kick in. If lenders have a hard time eking out a profit and bow out of the business, consumers may find themselves hard-pressed to obtain a mortgage with reasonable terms.

The mortgage-lending business has such narrow profit margins that banks need high volume to make money. Government intervention in the market, through such efforts as establishing the Home Affordable Refinance Program or keeping interest rates artificially low, created a surge in refinancing activity that benefited banks. But once that business dries up, home sales are going to need to pick up for banks to sustain mortgage gains.

At Wells Fargo, the biggest mortgage lender with 30 percent of the market, mortgage originations in the fourth quarter climbed 4 percent, to $125 billion, with refinancing accounting for 72 percent of that volume. But loan production was off from the record $139 billion in the third quarter, a sign that refinancing activity is slowing.

“Even if home purchase activity grows, it will not be enough to make up for the anticipated decline in refinancings,” said Guy D. Cecala, publisher of Inside Mortgage Finance.

He noted that refinancing activity is on track to account for about 72 percent of all mortgage activity in 2012, close to the same percentage as in 2003. The difference, however, is that 10 years ago the mortgage industry was pulling in $4 trillion in revenue, whereas last year the market took in an estimated $1.8 trillion, Cecala said.

Profits are nowhere close to what they were in the boom years, but considering that $2 trillion in earnings used to qualify as an average year, the market seems to be returning to some semblance of normalcy.

What’s more, evidence shows that banks may be able to count on the refinancing business for at least another year. According to housing data firm CoreLogic, more than 70 percent of mortgages had interest rates above 4 percent, meaning those borrowers could apply for a lower rate.

Even if mortgage refinancing tapers off, analysts are encouraged by the recovery of the housing market. Nearly all 12 of the Federal Reserve’s banking districts reported increases in home construction and home sales from mid-November through early January. The number of housing permits issued in November also rose 3.6 percent, according to the most recent numbers from the Census Bureau.

“The mortgage market is slowly starting to turn from refis to originations as the economy and the housing market improve,” said banking analyst Erik Oja at Standard & Poor’s. “The underlying trends — construction, permits — are strong.”

In an earnings call with analysts, JPMorgan chief executive Jamie Dimon agreed that the housing market has turned, which was reflected in the bank’s 33 percent jump in mortgage originations. JPMorgan, the second-largest home loan lender with 10 percent of the market, witnessed mortgage fees and related revenue jump to more than $2 billion in the fourth quarter from $723 million a year earlier.

Behemoth banks such as JPMorgan and Wells Fargo have gobbled up the mortgage market since the recession, as Bank of America and Citigroup stepped back to raise capital. Moody’s economist Mark Zandi anticipates the market will remain dominated by a few big players.

“These big mortgage companies are benefiting enormously because of the lack of competition, which means higher rates for consumers,” he said.

Mortgage bankers are recording higher gains from home loans as the gap widens between the interest rate they charge consumers and the rate they must pay investors who finance the loans by buying mortgage securities. Rates could be lower if banks had more competition.

Although it is unlikely the big banks will lose much share in the coming years, the new rules on qualified mortgages issued by the Consumer Financial Protection Bureau last week could lead to a shake-up in the market.

The bureau proposed an exemption for small creditors, which could give them an advantage, especially when they lend to low- and moderate-income communities.

Meanwhile, banking groups say the consumer bureau’s new rules for mortgage servicers — the intermediary firms that collect loan payments — will increase costs for homeowners as companies pass on the expense of revamping their systems.

But most analysts agree that the mortgage rules could ease uncertainties surrounding home lending and encourage a wider array of banks to lend. Besides, most of the big banks have already become more vigilant in handling home loans, especially in the wake of the torrent of mortgage fraud and foreclosure settlements.