It is thought that the Deuteronomic part of the Torah, and the Deuteronomistic history were originally composed as a single work, ever since the investigation of Martin Noth. Since Noth's work, some scholars attribute two separate stages to the text, a first (referred to as Dtr1) and second (referred to as Dtr2) edition of the text, although most still consider that both editions were the result of the same author.
The actual identity of the Deuteronomist is less secure than the body of his editing work: scholars postulate that the author was Baruch (Neriyah's son), Jeremiah's scribe, or possibly Jeremiah, due to the similarities in style between Jeremiah, and the inclusion in Jeremiah of direct (unattributed) quotes of D, as well as the affiliation of Jeremiah to the Shiloh priests, the time period at which Jeremiah lived.
In Deuteronomy, the Deuteronomist's literary style is that of elegant flashback told by Moses, and so much of the narrative is scattered and disordered. Nevertheless, when put together in sequence, the narrative mostly parallels those of JE and the priestly source, though it begins only at the Ten Commandments. Since the narrative is presented as the recollections of Moses, it obviously cannot contain memories of events prior to him; but the narrative's starting with the Ten Commandments (rather than with an earlier event in Moses' life) may simply be a convenient literary device, serving to imply that that is the moment that things which are worth remembering began. The Deuteronomist generally exhibits a stance similar to those of the Jahwist and Elohist, so it may be that the Deuteronomist's work was intended to be read in parallel with JE, rather than instead of it.
In contrast to the priestly source, the Deuteronomist cuts out the obviously pro-Aaronid tales, such as that of Aaron's flowering staff and that of the appointment of the Levites, but includes the story of the Golden Calf, which is the main story from JE that casts Aaron in a negative light. Indeed, Aaron is cast even more negatively in the Deuteronomist version of the Golden Calf story. The Deuteronomist also emphasizes the negativity of the Golden Calf story by cutting out the tale of the Nehushtan (which would cast the idea of a cult object in a positive light) and that of the heresy of Peor (which would dilute the Golden Calf story by presenting another wickedness, one in which Aaron is not the villain).
However, like the priestly source, the Deuteronomist avoids stories that contrast even mildly with its laws; for example, the tale of food being found in the desert doesn't involve sacrifice, and is cut. The tale of the non-Israelite prophet Balaam and the talking donkey is also cut, though this is most likely because it would appear out of place and disconnected from the main story.
King Hezekiah centralised the religion and destroyed places and objects of worship that were outside of the control of the Jerusalem Temple and its priesthood. The Assyrian empire invaded Judah shortly after Hezekiah died, and gained suzerainty. Subsequent kings of Judah, owing allegiance to the Assyrians, restored the places and objects of worship outside the temple. However, Hezekiah's great grandson Josiah instituted a new reform.
According to the narratives of 2 Kings and 2 Chronicles, in 622/621 BCE, Josiah's high priest Hilkiah found part of the Torah in the Temple, a mainly spartan and empty building. In reaction to the text, King Josiah again centralised the religion, and destroyed places and objects of worship which were neither the Jerusalem Temple nor specified to be housed in it. Since before the 5th century scholars (such as Jerome) have insisted that the text found by Hilkiah was the law code of Deuteronomy. Scholars allege that the text was written at Josiah's instigation and "found" to justify his actions.
According to the documentary hypothesis, the priests of Shiloh wrote the law code to support their views. The code was written to support the king, a centralised religion, Levites generally rather than just Aaronids, and a balance on the king's power (for example by supporting a militia rather than an organised army) due to the way in which kings had previously treated them.
D then created, according to the hypothesis, a history of rulers, judging them by their actions according to the code, culminating in Josiah. D inserted the law code at the start, framed as Moses' last words since D was not trying to change the pre-existing JE account. The purpose of this was to show that Josiah's rule was an act of God, Josiah being the hero to save Israel - a Moshiach. Josiah was the only person described as being comparable to Moses. The story of Josiah reflected the wording given by Moses in D, terms such as "do not turn, right or left", "and none arose like him", and "Love god with all your heart, all your soul, and all your might", are only ascribed to or of Moses and to or of Josiah in the whole of the Deuteronomical history. Parallels are not described between Moses and other kings.
D's history was composed by redacting earlier originally independent sources, and a few lines of text to provide a more continuous narrative, which included
The book referred to as Joshua was redacted together by associating each event with Joshua; the book of Judges by comparing each protagonist with the law code between the stories; the book of Kings by alternating between a king of Israel and that of Judah (both were originally covered in separate texts). At each alternation in the book of Kings, a description of the king's parentage, and an accession date compared to the reign of the king ruling in the other nation, is given.
Josiah died when he traveled to Megiddo to fight the Egyptian army (in a battle so famed among the Jews that it established Meggido as the traditional location for the eschatological final battle between good and evil) which was passing through Judah to support the Assyrians in their conflict with Babylon. The next kings, the first a son of Josiah, reversed the reform of Josiah, once more restoring the non-centralised holy places.
Egypt conquered Judah and exiled the king, replacing him with another of Josiah's sons, who was subsequently killed in a Babylonian attack and replaced by his son. Babylon eventually gained control of Judah, appointing a new king, who was a third son of Josiah. The king, after 10 years, rebelled against the Babylonian emperor Nebudchadnezzar, resulting in Nebudchadnezzar destroying Jerusalem, killing the whole of the king of Judah's family, and blinding and exiling the king himself.
Babylon decided to appoint a governor who would be favourable to it, choosing an anti-Assyrian from Judah. However, those connected to the family of King David, the royal dynasty that Nebudchadnezzar had extinguished, were so offended by this appointment that they assassinated the governor. The denizens of Judah, afraid of Nebudchadnezzar's response, almost entirely chose to become refugees, initially in Egypt. Nebudchadnezzar chose to burn Jerusalem to the ground, destroy the temple, and exile the remaining nobility and officials to Babylon as slaves. Judah no longer existed.
This posed some problems for the first edition of D. In its histories, it had implied that the dynasty of king David had been promised by God that it would rule Judah forever. In its text, it describes certain things as still existing which Nebudchadnezzar had destroyed. It describes Josiah as the saviour of Israel, but he had been killed, and his reforms undone.
D was edited. D couldn't be completely rewritten because the text was relatively well known. The text was added to by scattering references to the threat of dispersion of Judah amongst the nations should they disobey the law code. The promise of the survival of the royal family's reign was also amended to imply that, although it was true, it would be irrelevant if Judah did not exist to be ruled over. A curse was added threatening to send Judah back to Egypt, as had happened.
Another set of additions were references to the command against worshipping other Gods, including a description of God's last words to Moses, which describes the future destruction of Judah for this very crime. Additions were made to the histories emphasising the consequences of the undoing of Hezekiah's reforms that had occurred amongst his descendants.
Finally, a few additional sources appear to have been added into the text, and expanded on by other additions, specifically