David II lived from 5 March 1324 to 22 February 1371 and was King of Scotland from 7 June 1329 to 22 February 1371: though for short periods during that time Edward Balliol, who was backed by Edward III of England and was also crowned King of Scotland was in effective control of parts of the country. The wider picture in Scotland at the time is set out in our Historical Timeline.
David was the only son of Robert the Bruce and, in part due to his mother's imprisonment and his parents separation, was born late in Robert's life. Under the terms of the Treaty of Edinburgh & Northampton David was married, aged just four, to Princess Joanna of England, the sister of Edward III. He was still only four when he became David II of Scotland on the death of his father on 7 June 1329.
His succession to the crown caused immediate problems. The English had been quite happy to be paid 20,000 marks under the terms of the Treaty of Edinburgh & Northampton, but they then started questioning whether the other terms were enforceable given Edward III's age at the time the treaty was signed. They refused to return the Stone of Destiny to the Scots as provided for under the treaty. More importantly, Edward III, decided to support the claim of Edward Balliol, the eldest son of John Balliol to the Scottish crown in preference to the claim of David II.
With English support Balliol invaded Scotland, defeated the Scots at the Battle of Dupplin in Perthshire on 12 August 1332, and was made King of Scots at Scone on 24 September. In July 1333 Balliol and his English supporters were again victorious, this time at the battle of Haildon Hill. David and Joanna fled to Dumbarton Castle, en route to refuge in France. During much of David's absence the struggle between the Guardian of Scotland, Sir Andrew Murray, acting on David's behalf, and John Balliol supported by Edward III, flowed backwards and forwards. Balliol was only finally chased from the country by Sir Andrew Murray in 1337, when he found Edward III more interested in war with France than in yet another invasion of Scotland in support of Balliol's claim to the throne.
David returned to Scotland in June 1341, and took personal control of the country. In 1346 he invaded England in support of France. David lost the Battle of Neville's Cross on 17 October 1346 and was taken prisoner. He was to remain a fairly comfortably kept captive in England for eleven years, until the Treaty of Berwick was agreed in October 1357. This allowed David to return to Scotland in exchange for a vast ransom of 100,000 marks, payable in instalments. David had probably acknowledged Edward III as his feudal superior while in captivity, thus undoing his father's main achievement.
The Scots was able to pay a number of instalments of the ransom through heavy taxation of an already fragile economy, but David caused rebellion at home when he offered to name King Edward III or one of his sons the heir to the Scottish throne in return for writing off the debt. It seems likely that David continued secret negotiations with Edward to have Lionel, Duke of Clarence, declared his heir: and meanwhile there are suggestions he was using taxes raised to pay his ransom for his own purposes.
David died, without an heir, on 22 February 1371 in Edinburgh Castle. Through history Scotland had a mixed bag of monarchs: some excellent, like David's father Robert the Bruce, some much less so. There are probably few whose reign did so little for their country as David's. But given that he was married and crowned at the age of 4 and sent to France for safety at the age of 9, he never really stood much chance of developing into an effective king, and still less a good king. David was succeeded by his nephew Robert II, the first king of the House of Stewart.