Canada posted a smaller trade deficit in December as both exports and imports fell, but capped off the year with a surplus, the national statistical agency said Tuesday.

Beating expectations, the deficit narrowed to Can$160 million (US$120 million) in December from Can$219 million the previous month.

Exports decreased 1.2 percent to Can$63.0 billion mostly on lower exports of energy products, and imports -- driven by lower shipments of consumer goods -- fell 1.3 percent to Can$14.3 billion.

Canada still managed to post a second consecutive annual surplus -- widening from Can$4.6 billion in 2021 to Can$20.1 billion last year -- following a string of deficits from 2015 to 2020.

"The sharp rise in the annual trade surplus was primarily on account of higher exports (up 22 percent), which were mostly driven by strength in prices," Statistics Canada said in a statement.

"Imports (up 20 percent) also rose considerably in 2022," it said.

In December, energy exports were down significantly from a peak in June 2022, the agency said, as crude oil prices plummeted, coinciding with the temporary closure of a pipeline in the United States that carries Canadian crude oil.

Exports of wheat, canola and other crop products were also down, while a rise in exports of motor vehicles and parts partially offset decreases recorded in the previous two months.

Imports of consumer goods, meanwhile, fell for a third consecutive month, led by pharmaceutical products. This was due in part to lower demand for imported Covid-19 vaccines.

Canada also imported fewer passenger cars and light trucks in December.

But imports of refined petroleum products hit a record high, led by diesel and biodiesel fuels from the United States.