When the sun sinks beneath the horizon for an observer on the surface, the rays from the sun are still passing through the atmosphere above the observer. Indeed, once I sat on the beach and when the last remnant of the sun sank into the ocean, my wife, on the veranda of our hotel three stories higher, could still see the sun for several seconds (from this we estimated the radius of the earth, getting about 5000 miles).
The sun's rays passing through the higher regions of the atmosphere scatter light downwards, causing the 'twilight glow'.
The glow above is strongly purplish because of the presence of dust in the stratosphere, at an altitude of approximately 20 km (66,000 feet). Below is pictured the colorful twilight that we saw in Alaska from the eruption of El Chichon volcano in Mexico: