June 20 (Reuters) - Canada's main stock index rebounded from a near four-month low on Thursday as railroad stocks rallied and higher commodity prices lifted metal mining shares.

The Toronto Stock Exchange's S&P/TSX composite index ended up 65.45 points, or 0.3%, at 21,581.35, after it posted on Wednesday its lowest closing level since Feb. 29.

"The materials sector is really driving the market higher today," said Kevin Headland, co-chief investment strategist at Manulife Investment Management.

"We got a bit of a bounce back in the two rail companies as well. There is a bit of volatility recently in those two names due to the overhang of potential strike action."

The materials group, which includes metal miners and fertilizer companies, rose 1.9%, clawing back some recent declines, as gold and copper prices rallied.

Industrials ended 0.8% higher, with Canadian Pacific Kansas City Ltd gaining 2.3% and Canadian National Railway Co up 0.9%.

The Canadian trucking industry is on tenterhooks as talks between the Teamsters union, which represents more than 9,000 workers, and the country's two largest railroads drag on over a new contract.

Energy was also up, gaining 0.5%, as the price of oil climbed to a seven-week high. U.S. crude oil futures settled 0.7% higher at $87.17 a barrel.

Shares of Empire Company Ltd rose 5.4% after the food retailer reported better-than-expected quarterly earnings.

Among the sectors losing ground was information technology . It declined 0.6%, with Celestica Inc down 6.8%.

The utilities group closed lower for the tenth straight day, falling 0.8%, as bond yields moved higher. (Reporting by Fergal Smith in Toronto and Nikhil Sharma in Bengaluru; Editing by Shreya Biswas and Deepa Babington)