In the days of William the Conqueror, the French distinguished between a person living within a city and one living without.
They described them as deinsein and forain respectively, the first word being an Old French corruption of the Latin de intus, from within, and the second from Latin foras, without.
Both words were brought into England within the next few centuries and both meanings were at first retained. Later, under the influence of “citizen” the old deinzein became altered to denizen, and its meaning enlarged to include any inhabitant of a place, whether native-born or an alien entitled to the privileges of residence.
The original forain became, at first, forein, then some one in the sixteenth century, probably an ignoramus thinking to exhibit great learning, stuck a meaningless g in the word, mistakenly influenced by “deign” and “reign,” perhaps.
Thus it has come down to us as foreign. We still use it in the original sense, but more generally apply it to a person or thing of another nation or another country than our own.