Allegiance is a very Roman idea: strong loyalty to your team, your empire.
So it’s not surprising that the word itself comes from the Latin, ligare — to bind. Your allegiance is what binds you or ties you to your team.
From the Latin ligare, we get the Spanish… ligar, meaning the same, tying or binding!
Thus, the l-g root is clearly visible in both versions.