Sales at U.S. retailers rose for the first time in three months in May as expected, lifted by strong gasoline and building material receipts, according to a government report on Thursday that bolstered views the recession was abating.

The Commerce Department said total retail sales rose 0.5 percent after falling by a revised 0.2 percent in April, previously reported as a 0.4 percent drop.

Excluding motor vehicles and parts, sales rose 0.5 percent in May, compared to a 0.2 decline the prior month. Vehicles and parts sales rose 0.5 percent after a 0.4 percent fall in April.

Analysts polled by Reuters had forecast retail sales rising 0.5 percent in May. Excluding motor vehicles, sales had been predicted to gain 0.2 percent.

Gasoline sales jumped 3.6 percent in May after dropping 0.8 percent the previous month. Excluding gasoline, retail sales rose 0.2 percent. Sales of building materials climbed 1.3 percent in May, the biggest advance since April last year, after falling 0.6 percent in April.

Soft spots in the report included sales of electronic goods, which fell 0.5 percent in May after declining 0.9 percent the previous month.

(Reporting by Lucia Mutikani; Editing by Andrea Ricci)