We use matter power spectra from cosmological hydrodynamic simulations to quantify the effect of baryon physics on the weak gravitational lensing shear signal. The simulations consider a number of processes, such as radiative cooling, star formation, supernovae and feedback from active galactic nuclei (AGN). Van Daalen et al. (2011) used the same simulations to show that baryon physics, in particular the strong feedback that is required to solve the overcooling problem, modifies the matter power spectrum on scales relevant for cosmological weak lensing studies. As a result, the use of power spectra from dark matter simulations can lead to significant biases in the inferred cosmological parameters. We show that the typical biases are much larger than the precision with which future missions aim to constrain the dark energy equation of state, w_0. For instance, the simulation with AGN feedback, which reproduces X-ray and optical properties of groups of galaxies, gives rise to a ~40% bias in w_0. We demonstrate that the modification of the power spectrum is dominated by groups and clusters of galaxies, the effect of which can be modelled. We consider an approach based on the popular halo model and show that simple modifications can capture the main features of baryonic feedback. Despite its simplicity, we find that our model, when calibrated on the simulations, is able to reduce the bias in w_0 to a level comparable to the size of the statistical uncertainties for a Euclid-like mission. While observations of the gas and stellar fractions as a function of halo mass can be used to calibrate the model, hydrodynamic simulations will likely still be needed to extend the observed scaling relations down to halo masses of 10 ^12 M_sun/h.