The official definition of Dharma is:
prabhāvārthāya bhūtānāṃ dharmapravacanaṃ kṛtam
yat syād ahiṃsāsaṃyuktaṃ sa dharma iti niścayaḥ
dhāraṇād dharma ity āhur dharmeṇa vidhṛtāḥ prajāḥ
yat syād dhāraṇa saṃyuktaṃ sa dharma iti niścayaḥ
Righteousness was declared (by Brahman) for the advancement and growth of all creatures. Therefore, that which leads to advancement and growth is Righteousness. Righteousness was declared for restraining creatures from injuring one another. Therefore, that is righteousness which prevents injury to creatures. Righteousness (dharma) is so called because it upholds all creatures.
[The Mahābhārata, Śānti-parva, Bhīṣma responding to Yudhiṣṭhira]
It comes with a disclaimer:
tādṛśo 'yam anupraśno yatra dharmaḥ sudurvacaḥ
duṣkaraḥ pratisaṃkhyātuṃ tarkeṇātra vyavasyati
The question ('How should a person act who desires to adhere to virtue?') you have asked me is a difficult one, since it is difficult to say what righteousness is. It is not easy to indicate it. No one in discoursing upon righteousness, can indicate it accurately.
Kṛṣṇa defines it in a similar manner:
dhāraṇād dharmam ity āhur dharmo dhārayati prajāḥ
yaḥ syād dhāraṇa saṃyuktaḥ sa dharma iti niścayaḥ
Dharma protects and preserves the people. So it is the conclusion of the pandits that what maintains is Dharma.
[The Mahābhārata, Karṇa-parva, Kṛṣṇa speaking to Arjuna]
Kaṇāda in his Vaiśeṣika Sūtras defines dharma as:
यतोऽभ्युदयनिःश्रेयससिद्धिः स धर्मः ॥ १ । १ । २ ॥
Dharma (is) that from which (results) the accomplishment of Exaltation and of the Supreme Good.
Another translation:
That which leads to the attainment of Abhyudaya (prosperity in this world) and Niḥśreyasa (total cessation of pain and attainment of eternal bliss hereafter) is Dharma.