* Sharif, Modi to hold bilateral meeting
* Both leaders are focused on trade, economy
* Invitation could signal thaw in tensions (Updates with analyst comment)
By Sheree Sardar and Mehreen Zahra-Malik
ISLAMABAD, May 24 (Reuters) - Pakistan's Prime Minister Nawaz Sharif has accepted an invitation to attend the inauguration of Indian Prime Minister-designate Narendra Modi, a first in the history of the nuclear-armed rivals, an official said on Saturday.
"There will be a bilateral meeting on the sidelines between Prime Minister Nawaz Sharif and Mr. Modi," Mohyuddin Wani, the joint secretary of the prime minister's office, told Reuters. "Mr. Sharif will also be calling on the Indian president."
Pakistan and India have fought three wars since independence in 1947. Ties have been particularly tense since the 2008 attacks on Mumbai blamed by India on Pakistan-based militants.
Sharif came to power last year promising to rebuild relations with India but has been under pressure to toughen his stance from hardliners at home, particularly within the army.
The top source of friction is his aim to boost trade with India. Many army officers say India must vacate its part of the disputed territory of Kashmir before ties can improve.
In India too, former Prime Minister Manmohan Singh's efforts to rebuild economic and diplomatic ties fell apart when deadly skirmishes broke out along the border in Kashmir last year.
Modi's Bharatiya Janata Party has long advocated a tough stance on Pakistan, a view reflected in his election campaign that produced a parliamentary majority. The new Indian leader is seen as a hardliner on issues of national security.
Officials in Pakistan are also hopeful that Modi will seize an opportunity to rebuild ties, because he is much less vulnerable to the charges of weakness that plagued Singh.
"Both prime ministers are very business friendly and focused on the economy. Both have a majority in parliament and don't need a coalition," said Imtiaz Gul, the head of Islamabad think-tank the Centre for Research and Security Studies.
"This invitation is a positive step - it marks a break from the Cold War-era mentality that has overshadowed the relationship."
OPENING MARKETS, NORMALISING TRADE
Modi's ambitious economic agenda will require India to open markets and normalise trade with neighbours. He could find Sharif, a proponent of free markets with a history of conciliatory gestures towards New Delhi, an ally in that.
The relationship improved the last time the BJP took power, in 1998, under Prime Minister Atal Bihari Vajpayee, who rode a bus to Lahore during Sharif's previous stint in power to sign a peace accord.
Three months later, the Pakistani army torpedoed Sharif's attempts to improve ties by secretly sending soldiers disguised as militants to capture Indian outposts in the heights of Kargil, in the north of Indian Kashmir.
Lasting India-Pakistan peace would help smooth a potentially perilous transition in Afghanistan as most NATO combat forces prepare to leave by the end of this year.
Afghanistan has long been seen as a proxy battleground where Pakistan's Inter-Services Intelligence agency has been accused of sponsoring attacks on Indian targets.
India's consulate in the western Afghan city of Herat was attacked by heavily armed insurgents on Friday. All the insurgents were killed, an Indian official said, and five security guards were wounded.
Pakistan has long complained about the number of Indian consulates in Afghan cities, fearful that friendship between India and Afghanistan could leave it isolated.
On Friday, however, Pakistan's Foreign Ministry was quick to condemn the attack on India's Herat consulate, an indication that bilateral ties could be entering a new phase.
A Pakistani information ministry official said: "We still have to gauge what Modi's government's stand is on the many issues that remain unresolved between Pakistan and India.
"The inaugural speech will hopefully set the tone of relations and we can take it from there," the official said, requesting anonymity as he was not authorised to comment.
Former military ruler General Pervez Musharraf was the last Pakistani head of state to visit India, in 2005. Last year, Singh, then prime minister, declined Sharif's invitation to attend his oath-taking ceremony. (Writing by Katharine Houreld; Editing by Kim Coghill, Ron Popeski and Lynne O'Donnell)