New Delhi says Chinese troops crossed the de facto border and infiltrated Indian territory on April 15. About 50 Chinese soldiers pitched tents and camped in Depsang valley in the Ladakh region of eastern Kashmir, according to India.

China denied any incursion, saying its troops stayed on the Chinese side of the Line of Actual Control. As tensions rose, India moved soldiers into a position facing off the Chinese just 300 meters apart across the barren terrain.

Local army commanders from both sides held a series of meetings to resolve the crisis. India’s foreign secretary called in the Chinese ambassador to register a strong protest, while top officials conferred with their counterparts in Beijing and New Delhi.

Indian External Affairs spokesman Syed Akbaruddin said the governments agreed to pull their troops back to positions they held prior to the standoff. Border commanders met to work out the timing and arrangements, Akbaruddin said Monday.

Chinese Foreign Ministry spokeswoman Hua Chunying confirmed in a statement late Monday that the two countries had ended their standoff.

“China and India have reached an agreement on resolving the incident in the western section of the border. The frontier forces of the two countries have terminated the standoff at the Tiannan River Valley area,” Hua said.

India and China—neighbors with more than 1 billion people each—have had chilly relations since they fought a brief border war in 1962.

India says China is occupying 38,000 square kilometers of territory in the Aksai Chin plateau in the western Himalayas, while China claims around 90,000 square kilometers of land in India’s northeastern state of Arunachal Pradesh.

The two have held 15 unsuccessful rounds of talks to resolve the border dispute.

Other irritants remain in the relationship. China is a longtime ally and weapons supplier to Pakistan, India’s bitter rival. The presence in India of the Tibetan spiritual leader the Dalai Lama and the self-declared Tibetan government-in-exile is a source of tension. China is also suspicious of New Delhi’s growing ties with the United States.

Despite the territorial tensions, bilateral trade has soared, with China becoming India’s biggest trading partner. Two-way trade jumped from $5 billion in 2002 to nearly $75 billion in 2011, but declined slightly last year because of the global economic downturn. Trade remains heavily skewed in China’s favor, another source of worry for India.

Both countries appeared unwilling to let the latest spat over their largely undemarcated border upset their booming trade and relations that have improved over the last couple of decades.

Khurshid was scheduled to visit Beijing on Thursday to prepare for Li’s visit. But as friction over the boundary mounted, Khurshid made his China visit conditional on a Chinese troop withdrawal.

Analysts said both sides were keen to avoid worsening the crisis. If Khurshid had canceled his visit, it would have proved embarrassing for Li, who is making his first trip abroad after taking over as China’s premier two months ago.