TORONTO, April 8 (Reuters) - Canada's main stock index rose to a five-week high on Wednesday as investors cheered a ceasefire agreement between the United States and Iran, with technology and consumer discretionary shares contributing to broad-based gains.

The S&P/TSX Composite Index ended up 383.05 points, or 1.2%, at 33,620.57, marking its highest closing level since March 4.

The truce in the Middle East raised hopes for a resumption of oil and gas flows through the Strait of Hormuz, after supply shortages had led to a spike in energy prices, upending the outlook for the global economy.

"It's a big risk-on day today. It's a relief rally," said Michael Dehal, a senior portfolio manager at Dehal Investment Partners at Raymond James.

"The focus will be back on corporate earnings and the macro economic backdrop,"  Dehal said.

Canada's employment report for March is due on Friday. Economists expect a jobs gain of 15,000 after the economy shed 84,000 jobs in February.

In domestic politics, an opposition legislator defected to the ruling Liberal Party, leaving Prime Minister Mark Carney on the verge of a parliamentary majority that would make it easier to push through his agenda.

Priorities include spending on infrastructure, defense and housing as well as measures to enhance productivity.

The consumer discretionary sector rose 3.3%, with apparel retailer Aritzia Inc up 9.5% and automotive parts company Magna International Inc adding 5.5%. 

The materials group, which includes metal mining shares, added 2.3% as gold and copper prices benefited from a pullback in the safe-haven U.S. dollar.

Technology rose 2.4% and heavily weighted financials ended 1.9% higher.

Gains for the TSX were capped by losses for energy. The sector lost 4.5% as the price of oil settled 16.4% lower at $94.41 a barrel.

Vermilion Energy was among the biggest decliners, losing 7.4%, after the company announced an asset acquisition and first quarter production levels.

(Reporting by Fergal Smith and Utkarsh Tushar Hathi; Editing by Sahal Muhammed and Alistair Bell)

By Fergal Smith