Lennar Corp posted its first quarterly profit in almost three years, helped mainly by a tax benefit, and the news drove up its shares and those of other large homebuilders.

The company, one of the top five U.S. homebuilders, reported earnings of $35.6 million, or 19 cents per share, for the fourth quarter ended November 30, compared with a year-earlier loss of $811 million, or $5.12 per share. Revenue fell 29 percent to $913.7 million.

The latest results included a gain of $1.34 per share resulting from an extension of federal tax law allowing companies to apply losses to prior income.

Miami-based Lennar last made a quarterly profit in the first quarter of 2007.

Wall Street expected a loss of 48 cents a share before special items, on revenue of $862.7 million, according to Thomson Reuters I/B/E/S. Thomson Reuters could not immediately determine whether the results compared directly with estimates.

Lennar also said gross margin rose to 17.8 percent excluding charges, as it had less need for buyer incentives. Incentives accounted for 13.2 percent of home sales revenue, down from 16.4 percent a year earlier. Lower construction costs boosted margins as well.

Lennar's results were, in aggregate, a modest positive as we point to solid improvement in gross margins, JPMorgan analyst Michael Rehaut wrote in a note to clients.

During the quarter, homebuilders enjoyed a respite from the housing slump. Orders increased as buyers plunged into the market, emboldened by a federal tax credit, historically low interest rates and lower home prices.

Orders at Lennar increased by 3 percent in the fourth quarter, its first year-over-year increase since the first quarter of 2006. Its cancellation rate fell to 20 percent from 32 percent.

Lennar ended the quarter with $1.3 billion in cash. Several other builders also have robust balance sheets after spending the last several years trying to accumulate cash, even at the expense of profitability, in order to survive the slump.

Now the market is inching toward recovery, but builders' land assets continue to lose value, albeit at a slower rate than during the depths of the downturn. Lennar's results included charges of 89 cents per share in land valuation adjustments, the company said.

Lennar shares were up 8.4 percent at $14.85 in early trading, while No. 1 builder Pulte Homes Inc

rose 3.3 percent to $10.71 and D.R. Horton Inc gained 3.1 percent to $12.02.

(Reporting by Helen Chernikoff and Bijoy Koyitty, editing by Dave Zimmerman, John Wallace and Lisa Von Ahn)