The prime ministers of nuclear-armed rivals Pakistan and India have agreed at a rare meeting to co-operate on eliminating terrorism in south Asia, Pakistan's foreign ministry said.

In a sign of easing relations, Indian prime minister Narendra Modi also accepted his Pakistani counterpart Nawaz Sharif's invitation to attend a south Asian regional summit in Islamabad next year.

"Both sides condemned terrorism in all its forms and agreed to co-operate with each other to eliminate the menace of terrorism from south Asia," Pakistani foreign secretary Aizaz Ahmad Chaudhry said in a statement.

Mr Sharif and Mr Modi met in the Russian city of Ufa, where they are attending summits of the BRICS (Brazil, Russia, India, China and South Africa) trade group and the Shanghai Co-operation Organisation.

Pakistani television showed the pair shaking hands and smiling.

The hostility between Pakistan and India dates back seven decades, but strains have grown since nationalist Mr Modi took office a year ago. Last month, US secretary of state John Kerry voiced "enormous" concern over heightened tensions between the two countries.

Both sides have accused the other of fomenting terrorism. Pakistan alleges that India's spy agency is behind violence in the south-western Baluchistan province and north-western tribal regions.

New Delhi denies the charge, saying Pakistan should present solid evidence to back up its claim.

Meanwhile, India wants Pakistan to punish those who carried out deadly attacks in the heart of Mumbai in 2008 that left 166 people dead. Relations have deteriorated since April, when a Pakistani court freed Zaki-ur-Rehman Lakhvi, the suspected mastermind of the attacks, on bail.

Both sides agreed today to find ways to expedite the Mumbai case, Mr Chaudhry said.

He said security officials of Pakistan and India will meet in New Delhi to discuss all issues relating to terrorism. Officials overseeing Pakistani and Indian border issues will also meet, although he gave no dates.

India and Pakistan have fought two wars over Kashmir, which has been divided between them since British colonialists left in 1947.

At the Russian summit, president Vladimir Putin said India and Pakistan will join the Shanghai Co-operation Organisation, a group dominated by Russia and China and also including former Soviet republics in Central Asia.

Russia sees the organisation as a counterweight to Western alliances.

Membership potentially offers India greater access to the energy resources of Central Asia. Mr Modi has combined his attendance at the summit in Russia with visits to SCO members Kazakhstan, Kyrgyzstan, Tajikistan and Uzbekistan.

Mr Putin opened the annual summit by announcing the acceptance of India and Pakistan as members. He said Belarus would obtain observer status, joining Afghanistan, Iran and Mongolia.

The Russian president called for greater co-operation in fighting drug trafficking from Afghanistan and the financing of terrorism.