(Adds details)
OTTAWA, Aug 12 (Reuters) - Canada's trade deficit shrank to just C$55 million ($50 million) in June from C$1.1 billion in May as exports rose for the first time in four months and imports continued to fall, Statistics Canada said on Wednesday.
Analysts had on average predicted Canada would run a trade deficit of C$800 million in June.
Exports rose 2.3 percent to C$29.29 billion, thanks largely to 14 percent growth in shipments of energy products. Without the energy sector, overall exports would have fallen 0.5 percent.
Imports in June dropped 1.3 percent to C$29.34 billion -- the lowest since the C$27.1 billion recorded in January 2004 -- on lower volumes of machinery, industrial goods and other consumer goods.
Exports to the United States, which in June took 73 percent of all Canadian exports, rose 5.1 percent on the back of higher crude petroleum shipments.
Canada's trade surplus with the United States rose to C$3.1 billion in June from C$1.71 billion in May. ($1=$1.10 Canadian) (Reporting by David Ljunggren; Editing by John O'Callaghan)