Canada's main stock index closed barely lower on Wednesday, hurt by losses in energy shares as oil prices slid on a surprise inventory build, which offset positive comments from the U.S. Federal Reserve.

The Toronto Stock Exchange's S&P/TSX composite index ended the rollercoaster session down 3.46 points, or 0.02 per cent, at 14,546.54.

It pared losses from early in the session after the Fed held rates steady and said the risks to its outlook had diminished.

In a volatile session, the Dow Jones industrial average .DJI finished down a marginal 0.01 per cent at 18,472.17 points, the S&P 500 .SPX ended down 0.12 per cent at 2,166.58, and the Nasdaq Composite .IXIC added 0.58 per cent to 5,139.81.

"Clearly the headliner for today was the Fed and their policy statement, and that explains ... a little bit of the swings that we're seeing here late in the day," said Craig Fehr, Canadian market strategist at Edward Jones in St. Louis, Missouri.

The Canadian index turned lower earlier in the day as energy shares, a major component, were hurt by oil prices falling to three-month lows after the U.S. government reported a surprise build in crude and gasoline inventories during the peak summer driving season.

The heavyweight energy group, which had been trading higher before the inventory report was released, fell 1.6 per cent, with Suncor Energy Inc down 1 per cent at $34.66 and Cenovus Energy Inc losing 3.1 per cent to $17.50.

Six of the index's 10 main groups were in negative territory, with decliners just barely outnumbering advancers.

The most influential gainers included grocery chain Loblaw Cos Ltd, which rose 3.7 per cent to $73.45, and technology company CGI Group Inc, which jumped 7.2 per cent to $63.05, after both beat earnings expectations.

"We are starting to see the makings of a little bit of an earnings rebound," Fehr said, adding that it was still early days in Canada's earnings season and that more evidence was required to justify the TSX's valuation.

Toronto Star publisher Torstar Corp fell 6 per cent to $1.56 after reporting a wider loss and cutting its dividend.

The materials group, which includes precious and base metals miners and fertilizer companies, jumped 2.8 per cent as gold extended its climb above $1,330 an ounce after the Fed news..

Barrick Gold Corp surged 4.6 per cent to $28.22 and Goldcorp Inc jumped 3.1 per cent to $24.91.

Alaris Royalty Corp slumped 12.6 per cent to $25.64 after sharply missing earnings expectations and providing a weaker-than-expected outlook after markets closed on Tuesday.

Gildan Activewear Inc fell 5.6 per cent to $38.61 after reporting results and a weaker-than-expected outlook.