X-ray evidence for a mildly relativistic and variable outflow in the luminous Seyfert 1 galaxy Mrk 509