X-ray emission from stars much more massive than the Sun was discovered only 35 years ago. Such stars drive fast stellar winds where shocks can develop, and it is commonly assumed that the X-rays emerge from the shock-heated plasma. Many massive stars additionally pulsate. However, hitherto it was neither theoretically predicted nor observed that these pulsations would affect their X-ray emission. All X-ray pulsars known so far are associated with degenerate objects, either neutron stars or white dwarfs. Here we report the discovery of pulsating X-rays from a non-degenerate object, the massive B-type star x 1 CMa. This star is a variable of b Cep-type and has a strong magnetic field. Our observations with the X-ray Multi-Mirror (XMM-Newton) telescope reveal X-ray pulsations with the same period as the fundamental stellar oscillations. This discovery challenges our understanding of stellar winds from massive stars, their X-ray emission and their magnetism.