OTTAWA - The value of Canadian energy exports surged in May even as the industry was coping with a major Alberta wildfire, but improved oil sales were not enough to prevent the second biggest trade deficit on record, Statistics Canada data showed on Wednesday.

The $3.28 billion deficit, the 21st in a row, was much larger than the $2.70 billion shortfall predicted by analysts in a Reuters poll. The record high was the revised $3.32 billion seen in April.

Exports fell by 0.7 per cent as eight of 11 sub sectors declined, reflecting the Canadian economy's continued challenges as it tries to adjust to the prolonged and complex effects of an oil price slump.

Yet even as wildfires in the energy-producing province of Alberta forced the shutdown of several oil sands projects, higher prices helped the value of energy exports rise by 7.1 per cent, the highest month-on-month advance since May 2014. The value of exports of crude oil and crude bitumen surged 10.5 per cent.

Statscan said early evidence indicated that Canadian refinery activity declined in May, freeing up crude oil supply for export. It said the remaining shortfall was largely met by a drawdown of Alberta inventories.

"It's almost counterintuitive. It's not what we were expecting to see at all," said Peter Hall, chief economist at Export Development Canada.

Hall said a particular concern was a 21.0 per cent drop in exports of unwrought precious metals and precious metal alloys, largely due to weaker demand in Britain and China. The sector is known for its volatility, he added.

Bank of Montreal chief economist Doug Porter said he was surprised by the weakness in non-energy exports, given the strong U.S. economy and a Canadian dollar that has slipped against its U.S. counterpart.

"I don't think there's a single reason to explain why exports have been disappointing," he said.

Imports dropped by 0.8 per cent, in part due to lower imports of aircraft and other transportation equipment and parts.

Exports to the United Kingdom fell 45.4 per cent in May. Meanwhile exports to the United States, which accounted for 78.0 per cent of Canada's global total in May, rose by 3.6 per cent while imports fell by 1.1 per cent. As a result, Canada's trade surplus with the U.S. widened to $2.76 billion from $1.31 billion in April.

The Bank of Canada, citing the wildfire impact, said last month that growth was likely flat or slightly negative in the second quarter. It sees an outsized third-quarter recovery.

With files from BNN