We report on two XMM-Newton observations of the planetary host star HD 189733. The system has a close in planet and it can potentially affect the coronal structure via interactions with the magnetosphere. We have obtained X-ray spectra and light curves from EPIC and the Reflection Grating Spectrometer on board XMM-Newton which we have analyzed and interpreted. We reduced X-ray data from the primary transit and secondary eclipse that occurred on 2007 April 17 and 2009 May 18, respectively. In the 2007 April observation, only variability due to weak flares is recognized. In 2009 HD 189733 exhibited an X-ray flux that was always larger than in the 2007 observation. The average flux in 2009 was higher than in the 2007 observation by a factor of 45%. During the 2009 secondary eclipse we observed a significant softening of the X-ray spectrum at a level of ~3?. Furthermore, we observed the most intense flare recorded at either epoch. This flare occurred 3 ks after the end of the eclipse. The flare decay shows several minor ignitions perhaps linked to the main event and hinting at secondary loops that are triggered by the main loop. Magnetohydrodynamic (MHD) simulations show that the magnetic interaction between planet and star enhances the density and the magnetic field in a region between the planet and the star because of their relative orbital/rotation motion. X-ray observations and model predictions are globally found in agreement, despite the quite simple MHD model and the lack of precise estimate of parameters including the alignment and the intensity of stellar and planetary magnetic fields. Future observations should confirm or disprove this hypothesis, by determining whether flares are systematically recurring in the light curve at the same planetary phase.