Canada's benchmark stock index reversed earlier gains on Wednesday as weaker energy and materials stocks offset a rally in Canadian Pacific Railway shares following better-than-expected quarterly earnings.

Oil and gas companies gave back 0.4 per cent as crude prices pared gains following an unexpected fall in U.S. refining rates and diesel and gasoline stock builds that indicated softer demand.

Stormy weather that caused power outages in parts of Alberta and Saskatchewan also disrupted two crude oil pipelines in Western Canada.

Enbridge Inc's (ENB.TO) 2.6 per cent retreat to $50.42 accounted for about a tenth of a per cent of the index's decline. Transcanada Corp (TRP.TO) fell 2.2 per cent at $61.96.

Encana Corp (ECA.TO), which holds its investor day on Wednesday, tempered some of declines, rising 2.8 per cent to $14.70.

CP Rail (CP.TO) also stemmed losses and finished up 5.1 per cent to end at $220.36 after the company also raised its full-year profit forecast.

The results gave a boost to its peer, Canadian National Railway (CNR.TO), which gained 0.7 per cent to end at $101.05. The two companies helped lift the industrials sector 1.2 per cent.

The Toronto Stock Exchange's S&P/TSX composite index closed down 34.74 points, or 0.22 per cent, to finish at 15,782.16. Half of the index's 10 main sectors lost ground.

The index, which is flirting near highs reached in February, has see-sawed back and forth this week after rallying more than five per cent since early September.

"It's much better to have two steps forward, one step back. That's a lot more normalizing in our opinion," said Sid Mokhtari, market technician and director of institutional equity research at CIBC World Markets.

"There's a little bit of a pullback in the commodities related areas," he added.

Mining stocks were squeezed by metal prices, with gold prices falling for a third straight session as the greenback rose amid speculation over who will be the next chair of the U.S. Federal Reserve.

Copper prices also fell on profit-taking after its recent surge to three-year highs, though demand expectations from China helped curb losses.

Teck Resources (TECKb.TO) fell nearly 2 per cent to $27.61, while Barrick Gold (ABX.TO) fell 0.8 per cent to $20.16. Agnico Eagle Mines (AEM.TO) was down 1.1 per cent at $55.84.

The materials sector lost 0.8 per cent, while the gold subsector retreated 1.3 per cent.