The Legend of Aqhat, one of the great epic myths preserved in the Ugaritic archive at Ras Shamra, was popular in some form in Israel and Judah and shows its traces in the OT and later Jewish literature. Ezekiel 14:12-20, 28:1-3 makes several passing references to the legend and its hero, an ancient semi-divine king named Danel renowned for his wisdom and healing powers. Danel was one of the Rephaim, a primeval race of demigod kings who linger on as spirits in Sheol and who were revered by the Canaanites in ancestor worship (cf. Job 26:5, Proverbs 9:18, 21:16, and especially Isaiah 14:9 which refer to the Rephaim as the ghosts of dead kings and the dead in general, and Genesis 14:5, Deuteronomy 3:13, and 2 Samuel 21:16, 18 which refer to them as the ancient aboriginal inhabitants of Canaan, of gigantic stature like the Nephilim). Ezekiel 28:1-3 alludes to Danel's famed wisdom and 14:12-20 alludes to the death and rebirth of his son Aqhat. In the Ugaritic version of the legend, the divine craftsman Kothar bequeathed the newborn Aqhat with a bow made in his heavenly workshop but the war goddess Anat wanted the bow for herself, and after a long struggle to convince the youth to give it up, she dispatched two monsters to kill the boy. Having lost his only heir, Danel cursed the land and El, feeling pity on the king, blessed the king and brought back his son to life -- blessings reminiscent of Job in Job 42:10-17. Thus Danel was "able to save [his] son", as Ezekiel 14:12-20 says of him, comparing him to Job and Noah (who also saved his family). There are later scattered allusions to the Legend of Aqhat in 1 Enoch 6:7, 69:2 and Jubilees 4:17-21.
There may be additional allusions, even direct quotations, of the tale in the David Cycle of 1 and 2 Samuel -- raising the possibility that much of the lore on the exploits of Kings David and Solomon draws on legendary material on ancient Rephaim kings like King Danel and King Keret. It is curious, for instance, that David fights against various warriors "descended from the Rapha of Gath" in 2 Samuel 21:15-22, and in the Aqhat legend Danel himself is called "a Rapha man" (CTA 17 i 1), and that according to a late tradition in 1 Chronicles 3:1, David had a son named dny'l "Daniel" (compare the dn'l "Danel" of Ezekiel and the Aqhat legend). Danel's wisdom in "judging the cause of the widow, adjudicating the case of the orphan" (CTA 19 i 24-25) is reminiscent of the legendary wisdom of David's successor Solomon (1 Kings 3:16-28). King Keret is called a "son of El" in CTA 16 i 2-23, like David is called God's "son" in 2 Samuel 7:14. Unlike Danel, however, David has little problem fathering children. Danel's plight is closer to that of Job and Abraham, who faced the prospect of giving up his only son through Sarah (Isaac) as a sacrifice.
However, in 2 Samuel 1 David learns of the deaths of Saul and Jonathan (whom he loved) and his reaction closely resembles the portion of the Aqhat legend where Danel laments over the death of Aqhat. First, Danel's daughter Pugat in grief "tore the garment of Danel the Rapha man, the cloak of the valiant Harnamite man" (CTA 19 i 93-94). Likewise David "took hold of his garments and tore them, and all the men with him did the same" (2 Samuel 1:11). Then in righteous anger Danel casts a spell of drought "upon the clouds in the heat of the season". David similarly curses the "mountains of Gilboa" where Saul and Jonathan were slain. The language shows near verbatim resemblance with two texts in 2 Samuel. First, compare the curse of Danel with the curse of David:
"For seven years Baal shall fail, for eight (years) he who rides upon the clouds. No dew (tl), no rain, no welling up (sr') of the deeps (thmtm), no goodness of Baal's voice." (CTA 19 i 42-45)
"O mountains of Gilboa, let there be neither dew (tl), nor rain upon you, nor rising up (wsr') of the two deeps (thwmt), for there the hero's shield was dishonored." (2 Samuel 1:21)
Both give a three-fold curse against life-giving water from any of the three natural sources: dew, rain, or springs. There is a late reflex of Danel's curse in 1 Enoch 6:6-7, 13:9 where the defiled angels mourn in Abiline (cf. Abilim where Aqhat was slain) and bind themselves with a curse on Mount Hermon (cf. Danel's appellation "the Harnamite"), and a fragment of the Book of Noah (derived from a lost Enochian work) which states that because of the actions of the rebel angels "cold shall not depart forever, nor snow, nor hoarfrost, and dew shall not descend on it except for a curse" (Book of Noah, 14). According to 1 Enoch 6:6-7, one of these angels who inflicted the curse was named Danel. In the Canaanite legend, Danel later curses the giant hawks that Anat had sent to kill Aqhat, beseeching Baal to smash their wings and tear open their stomaches so Danel can bury his son's bones. Here again we find a verbal reminiscence with the Davidic psalm in 2 Samuel 22 (= Psalm 18):
"He bent the heavens down and came down, a dark cloud under his feet; he mounted a cherub and flew and soared on the wings of the wind.... Yahweh thundered from heaven and made his voice heard; he let his arrows fly and scattered them, launched his lightnings and routed them.... I pursue my enemies and destroy then, no turn back till an end is made for them; I strike them down, and they do not rise, they fall, they are under my feet" (2 Samuel 22:10-11, 14-15, 38-39)
"For seven years Baal shall fail, eight years he who rides upon the clouds.... May Baal break the wings of the hawks, may Baal break their pinions, so that they fall down at my feet. (CTA 19 i 42; ii 106)
In the Ugaritic text, Danel calls on Baal to curse the land and accomplish his wishes, just as David describes Yahweh's assistance at his hour of need. The Davidic psalm is rich in Baalist meterological imagery, from description of the thunderous voice and lightning arrows to the movement with the storm clouds. The statement that Baal "rides upon the clouds" matches the remark about Yahweh mounting a cherub and soaring "on the wings of the wind" with "a dark cloud under his feet". Aqhat calls on Baal to vanquish his enemies "so that they fall down at my feet," and similarly "David" says that his enemies "fall, they are under my feet". While the dependence is likely not direct, there is a commonality in language and theme here.