You establish Dm during your song, in both lines. The second last chord is expected to be Eº or Eø diatonically, but instead you use
- Em for the first line (so Bb in the scales becames altered Bb->B)
- E for the second line (so Bb and G became Bb->B and G->G#)
For the first line you are stepping within minority from an A natural minor scale to an A melodic minor scale (V grade, Mixolydian b6), but I think it's safer to simply say we are modulating from natural minor to dorian. If it's a temporal "chromatic" modulation or not, we can only tell by hearing the overlapped melody notes (since we don't know in which mode does the ambiguous Em plays).
For the second line you are stepping within minority from an A natural minor scale to an A harmonic minor scale (IV grade, Dorian#4, the "Romanian" scale), which is normally more "hearable" as it keeps the (b3,)b6 alteration structure for which the minor scales have sense when harmonizing in thirds. You can assume the Harmonic minor function as you end with an A (probably it's not casual, you felt it was called), which specially if its A7, claims for the Dm again (V7-I is the typical cadence for Hm).
This is same use as in Tico-Tico Na fubá (typical accordion song): Dm-A7-Dm. Gm-Dm, E7-A7-Dm (in D as yours) [it certainly has these romanian fanfar feel]
Tico-Tico Na Fubá
Am-E7-Am, Dm-Am, B7-E7-Am
You are moving in fifths taking profit of this V7-I power V7-of-V7-of-I, V7-of-I, I, it's like a modal interchange in between the harmonic scale. Blues uses oftenly this principle as well.
E G# B D = E7 = V7 of Am
| V V |
E A C (D) = Am(add11) = I of Am
Leading note is clear, semitone moving creates a perfect fit strength, as G# moves to A whilst B does the same to C, and meanwhile the other notes are fixed.