(Reuters) - A brief meeting between India's Prime Minister Narendra Modi and his Pakistani counterpart on Thursday salvaged a summit of South Asian leaders, with all eight countries clinching a last-minute deal to create a regional electricity grid.

The pact at the summit's closing ceremony in the Nepali capital, will buttress Modi's ambition for South Asia to become a viable economic counterweight to China, which has made sweeping inroads in the region.

Modi shook hands with Pakistani Prime Minister Nawaz Sharif at a mountain retreat outside Kathmandu and then again before the curtain went down on the conference. Television showed the two men smiling and exchanging a few words.

"Both are talking in a friendly manner," Nepal Prime Minister Sushil Kumar Koirala told reporters, when asked if his country, as summit host, had helped break the ice.

Except for these brief exchanges, the two leaders had spent most of the summit cold-shouldering each other, however.

India and Pakistan have fought three wars since independence from Britain in 1947. On Thursday, the worst militant violence in more than a year in the Indian part of disputed Kashmir killed ten people, including three Indian soldiers.

The squabbling between the rivals is widely blamed for the poor performance of the South Asian Association for Regional Cooperation (SAARC), initially founded with the goal of moving towards a European-style union.

Despite a free trade pact in force since 2006, high tariffs and curbs on movement limit trade among South Asian nations to just five percent of their total trade.

The grouping's failure to foster closer ties over the past three decades has left the way open for China to step in, by helping to build ports and roads.

China has observer status at the grouping. Vice Foreign Minister Liu Zhenmin on Wednesday promised $30 billion for road building in South Asia over five years, and suggested increasing trade to $150 billion over the same period.

Modi announced an easier regime for business and medical visas and promised to lower India's trade surplus.

Pakistan, which still refused to sign two other planned pacts to boost cross border road and rail traffic, was increasingly sidelined at the summit.

India and Pakistan have been trying for years to strike a deal to share energy across their heavily militarized border in Punjab, but Pakistan's army has resisted the effort. After Thursday's pact it was not immediately clear if the army was on board.