NEW DELHI — India and China agreed on Monday to back away from their confrontation over a tiny slice of territory high in the Himalayas, easing tensions between the world’s two most populous countries.

For weeks, worries had been growing of a major conflict between the two nuclear powers, in what had developed into one of the worst border disputes between the countries in 30 years — punctuated by a rock-throwing, chest-bumping fracas between the Chinese and Indian soldiers.

Both sides agreed to give some ground in order to end the standoff. In a short statement, the Indian government said it had reached an “understanding” with Beijing and had agreed to an “expeditious disengagement” along the border, pulling back troops who had been sent to the disputed area to block the Chinese from building a new road.

China seemed willing to compromise as well, still claiming the disputed territory, but making no mention in its statements on Monday that it was continuing to build the contentious road.