This is part of the “Deuteronomy 32 Worldview.” Most translations translate verse 17 along the lines of the ESV.
“They sacrificed to demons that were no gods, to gods they had never known, to new gods that had come recently.”
This gives the idea that Israel sacrificed to non-existent verbal fictions. But as Heiser, and to a lesser extent John Walton, have shown, the text, when translated properly, says the opposite. I am going to quote the passage again and put the Hebrew in parentheses.
“They sacrificed to demons (shedim) that were no gods (eloah), to gods (elohim) they had never known, to new gods (elohim) that had come recently.”
This is very different. “Eloah” is a defective noun that is singular, which means that Israel sacrificed to something other than the true God. Demons here are shedim. Shedim comes from the Akkadian shadu, which means guardian spirit of the underworld. It is a territorial term. The ESV gets the rest of it correct.
The point is that the shedim are in the category of elohimic beings; only that they are not the supreme God (Elohim).