We have searched for solar axions or other pseudoscalar particles that couple to two photons by using the CERN Axion Solar Telescope (CAST) setup. Whereas we previously have reported results from CAST with evacuated magnet bores (Phase I), setting limits on lower mass axions, here we report results from CAST where the magnet bores were filled with hefour gas (Phase II) of variable pressure. The introduction of gas generated a refractive photon mass $m_gamma$, thereby achieving the maximum possible conversion rate for those axion masses ma that match $m_gamma$. With 160 different pressure settings we have scanned ma up to about 0.4 eV, taking approximately 2 h of data for each setting. From the absence of excess X-rays when the magnet was pointing to the Sun, we set a typical upper limit on the axion-photon coupling of $gaglesssim 2.17times 10^{-10} {rm GeV}^{-1}$ at 95% CL for $ma lesssim 0.4$ eV, the exact result depending on the pressure setting. The excluded parameter range covers realistic axion models with a Peccei-Quinn scale in the neighborhood of $f_{rm a}sim10^{7}$ GeV. Currently in the second part of CAST Phase II, we are searching for axions with masses up to about 1.2 eV using hethree as a buffer gas.