(This story has been corrected to say the index hit a near three-month, not a near three-week, high in the headline and paragraph 1)

(Reuters) - Canada's main stock index rose to a near three-month high on Monday as the United States and China reached a deal to reduce tariffs, raising optimism that an all-out trade war disrupting the global economy can be avoided.

The Toronto Stock Exchange's S&P/TSX composite index ended up 174.44 points, or 0.7%, at 25,532.18, its highest closing level since February 19.

U.S. stocks posted sharper gains, clawing back some recent underperformance against the Toronto market.

The TSX has been shielded in a turbulent period for markets by its cheaper valuation compared to Wall Street and a heavy weighting in gold-mining shares, say analysts.

"Canadian markets can benefit from the big easing in trade tensions (as) it shows that the tariff war may be able to get resolved more quickly than people had previously thought", said Colin Cieszynski, chief market strategist at SIA Wealth Management.

The technology sector gained 5.5% as shares of e-commerce company Shopify Inc 14.1%.

The price of oil settled 1.5% higher at $61.95 a barrel, boosting energy which added 3%.

Consumer discretionary was up 2.4% as shares of apparel retailer Aritzia Inc and auto parts company Magna International Inc jumped.

Some of gold's safe-haven attraction faded which weighed on the materials group. The group was down 4.9%.

Shares of Pan American Silver Corp tumbled 15.9% after a deal to acquire MAG Silver Corp. MAG Silver shares gained 5.5%.

Hudbay Minerals Inc shares jumped nearly 9% after the miner's first-quarter results beat estimates.

(Reporting by Fergal Smith in Toronto and Sanchayaita Roy and Sukriti Gupta in Bengaluru; Editing by Vijay Kishore and Alistair Bell)

By Sukriti Gupta and Fergal Smith