He was educated at Eton, and studied law at Utrecht. In 1748 upon his return to Scotland from Utrecht he was admitted an Advocate. It is said that as a pleader he attained neither high distinction nor very extensive practice, but he rapidly established a well-deserved reputation for sound knowledge, unwearied application and strict probity, and in 1766 he was elevated to the bench in the Court of Session where he assumed the title of Lord Hailes. Ten years later he was appointed a Lord of Justiciary.

He was twice married: (1) in 1763, to Anne, daughter of Sir George Broun, Lord Coalston, a Lord of Session, by whom he had a daughter, Christian (d.1838). He remarried (2) March 20, 1770, Helen (d. 1799), daughter of Sir James Fergusson, Baronet, of Kilkerran, Ayrshire, by whom he had another daughter, Jean (d.1803) who married her cousin, James Fergusson, Esq., and left issue.

Upon the death of Lord Hailes, his baronetcy passed to his nephew, James, 3rd Bt., the son of his brother John Dalrymple, Lord Provost of Edinburgh.

Lord Hailes's most important contribution to literature was the Annals of Scotland, of which the first volume, From the accession of Malcolm III, surnamed Canmore, to the accession of Robert I, appeared in 1776, and the second, From the accession of Robert I, surnamed Bruce, to the accession of the house of Stewart, in 1779. It is, as his friend Dr Johnson justly described this work at the time of its appearance, a "Dictionary" of carefully sifted facts, which tells all that is wanted and all that is known, but without any laboured splendour of language or affected subtlety of conjecture.

In 1786 he published An Inquiry into the Secondary Causes which Mr Gibbon has assigned for the Rapid Growth of Christianity (Dutch translation, Utrecht, 1793), one of the most respectable of the very many replies which were made to the famous 15th and 16th chapters of the Decline and Fall of the Roman Empire. A Memoir of Lord Hailes is prefixed to the 1808 reprint of his Inquiry into the Secondary Causes.