Sunrise and sunset are the instants when the upper edge of the Sun appears and disappears over the horizon respectively as a result of Earth's rotation. They are also affected by the atmospheric refraction when sunlight passes through the atmosphere.
The density of the atmosphere is not even and decreases with increasing altitude. At a result, when sunlight passes through the atmosphere, successive refraction occurs and bends the sunlight towards the ground. If we look towards the Sun, the altitude of the observed Sun's image (i.e. the apparent position of the Sun) will be higher than the actual location of the Sun. Therefore, sunrise occurs before the Sun actually reaches the horizon similarly, the Sun truly disappears below the horizon before sunset happens.