OTTAWA -- The economy grew at an annual rate of 1.8 per cent in the second quarter, as companies increased investment in equipment and added substantially to their inventories.

The pace of growth was slightly higher than economists' expectations and nearly in line with the Bank of Canada projection for 1.9 per cent.

But it's the third quarter in a row for sluggish economic performance below two per cent.

"The Canadian economy did slightly better than expected in the second quarter, but the pace was still nothing to write home about," Douglas Porter, deputy chief economist at BMO Capital Markets, said in a note to clients.

"The economy is essentially growing right in line with the U.S. now and is still rising below potential."

Statistics Canada said business investment was mainly responsible for keeping the economy afloat from April to June -- as if on cue in the wake of scoldings from the Bank of Canada and federal government, who recently chided companies for sitting on their spare cash.

The agency said investment in plant and equipment grew at its fastest pace since this time last year, up 2.3 per cent from the previous quarter. Purchases of transportation equipment and industrial machinery were particularly strong.

And non-farm inventories surged during between April and June. Businesses increased their inventories by $15.2 billion in the second quarter -- $7 billion more than in the first three months of the year.

But demand for exports slowed and imports rose substantially, dragging down overall growth.

In June, gross domestic product grew 0.2 per cent from May, propelled by output in the mining, oil and gas sector. Output declined in the wholesale and retail trade sectors, as well as manufacturing.

Sluggish economic growth prompted a warning from Ottawa on Friday.

The Finance Department recorded a shrinking deficit for the first three months of the 2012-20113 fiscal year, but cautioned that the fiscal outlook is at risk of deteriorating.

In its monthly Fiscal Monitor, the department said the deficit for the first three months of the 2012-13 fiscal year was $2 billion -- less than half the $4.2-billion recorded for the same period last year.

The department said that's consistent with its plan to reduce the 2012-2013 deficit to $21.1 billion.

But it also warned that a weak economy poses a mounting risk for the fiscal situation.

From April to June, federal revenues rose 4.7 per cent because of higher income tax payments and a hike in the Employment Insurance rate, while expenses rose at a more modest pace.

For the month of June alone, the deficit was $1.1 billion, compared with $2.3 billion for June 2011.