An uptick in home sales and selling prices pushed homebuilder KB Home (KBH) to a third-quarter profit of $3.3 million, or 4 cents a share, for the quarter ending Aug. 31.

That is up from a net loss of $9.6 million, or 13 cents a share, a year earlier. The builder's report surprised Wall Street, where analysts forecasted an average loss of 16 cents a share, according to Yahoo! Finance data.

The builder also posted total revenue of $424.5 million, an increase from $367.3 million a year ago. That jump in sales is tied to more purchases and higher selling prices.

KB delivered 1,720 homes during the period, up 7% from 3Q of 2011. The homes sold featured an average selling price of $245,100, which is an 8% increase from 12 months earlier.

"We are pleased to report a profit for the third quarter," said Jeffrey Mezger, president and chief executive officer. "During the quarter, we continued to generate improvement in several key financial and operating metrics. The favorable year-over-year performance in our deliveries; revenues; operating income; net orders; and backlog were particularly encouraging as we operated with fewer communities."

KB's positive earnings report comes at a time when mild housing recoveries are popping up in various markets across the U.S. The builder noted that housing inventories in key markets are starting to decline, a catalyst for new home construction.

"In particular, we are seeing dramatic improvement in California, where we are the state's largest homebuilder, as the continued strengthening in the coastal markets is now spreading inland to Sacramento, the Central Valley and the Inland Empire," Mezger said.