We report on simultaneous X-ray and radio observations of the radio-mode-switching pulsar PSR B1822-09 with ESAs XMM-Newton and the WSRT, GMRT and Lovell radio telescopes. PSR B1822-09 switches between a radio-bright and radio-quiet mode, and we discovered a relationship between the durations of its modes and a known underlying radio-modulation timescale within the modes. We discovered X-ray (energies 0.2-1.4 keV) pulsations with a broad sinusoidal pulse, slightly lagging the radio main pulse in phase by 0.094 +/- 0.017, with an energy-dependent pulsed fraction varying from ~0.15 at 0.3 keV to ~0.6 at 1 keV. No evidence is found for simultaneous X-ray and radio mode switching. The total X-ray spectrum consists of a cool component (T ~ 0.96 x 10^6 K, hot-spot radius R ~ 2.0 km) and a hot component (T ~ 2.2 x 10^6 K, R ~ 100 m). The hot component can be ascribed to the pulsed emission and the cool component to the unpulsed emission. The high-energy characteristics of PSR B1822-09 resemble those of middle-aged pulsars such as PSR B0656+14, PSR B1055-52 and Geminga, including an indication for pulsed high-energy gamma-ray emission in Fermi LAT data. Explanations for the high pulsed fraction seem to require different temperatures at the two poles of this orthogonal rotator, or magnetic anisotropic beaming effects in its strong magnetic field. In the X-ray skymap we found a harder source at only (5.1+/- 0.5 )arcsec from PSR B1822-09, which might be a pulsar wind nebula.