This is more about explaining why, as a non-native speaker, I share your confusion than it is about trying to explain the subtle differences that you seek, but I think the focal point of my confusion is where the word “falloir” overlaps the two verbs/phrases at issue.
See Reverso’s meaning #4 under its Définition entry for “falloir” and synonym #s 1 and 2 under its Synonyme entry for it here and below:
falloir v (Dictionnaire Français Définition)
1 être nécessaire (après le carrefour, il faut
rouler encore trois kilomètres)
2 être indispensable (il faut
avoir lu ce livre pour en parler)
3 être utile (il faudrait un
4 avoir besoin (pour avoir du temps, il faut de l'argent)
5 être dans l'obligation (il va falloir y aller)
6 être probable
(faut-il être bête)
7 être fatalement (il a fallu qu'il y aille)
8 manquer, faire défaut
9 être obligatoire
falloir v (Dictionnaire Français Synonyme)
1 devoir, nécessiter, redevoir
2 nécessiter, devoir
With this direct overlapping connection by way of "falloir" (in meaning #4 and synonym #s 1 and 2) in mind, I think it's logical, or at least understandable to associate falloir's notions of "being necessary" (#3) and "being [under] an obligation" (#4) with both "avoir besoin" and "devoir."
Analyzing the difference between French's "avoir besoin [de]" and "devoir" by analyzing the difference between English's "need" and "have to/must" is indeed helpful, but there is, similar to the one discussed above between the French words at issue, an important overlapping connection between the two English terms that I feel deserves further examination, to-wit:
need: (modal verb) To be obliged or required (to do something).
"You need not go if you don't want to."
must: (modal auxiliary, defective) To do as a requirement; indicates
that the sentence subject is required as an imperative or directive to
execute the sentence predicate, with failure to do so resulting in a
"You must arrive in class on time." — the requirement is an imperative
(both from this answer with emphasis added)
Personally, I feel that the Wiktionary entry for "need" quoted above has skirted the overlap issue by providing an example using the negative "need not," for when used in the negative, "need not" doesn't overlap at all with "must not" in the "obliged or required (to do something)" sense of the word "need."
When not used negatively, however, I see little or no difference between:
"I need/have to go/leave right now ..." and
"I must go/leave right now ..." (... "because my wife's waiting and she'll kill me if I'm late") in English, ...
... and except for the subtle, external/internal, difference mentioned in this answer, I don't see much difference between:
"j'ai besoin de m'en aller/de partir ...",
"je dois m'en aller/partir ..." or even
"il faut [que je parte] partir ..." ("... car ma femme m'attend ...") in French.