Recently, the emerging intelligent reflecting surfaces (IRS) has been leveraged to establish a smart and controllable wireless environment. This paper addresses the challenge of maximizing spectral efficiency in an IRS-aided downlink multi-user system while facing jammer attacks. The optimization problem focuses on improving the available transmission rate and limiting the impact of malicious jammer signals. The efficiency of the IRS in anti-jamming communications is achieved by determining the optimal phase shifts of the IRS elements and the optimal beamforming at the base station (BS). The optimization problem is non-convex. To tackle this non-convexity, an alternating optimization algorithm is proposed, dividing the main problem into two sub-problems which are solved using the semi-definite relaxation (SDR) and Gaussian randomization techniques. The simulation results confirm the enhanced spectral efficiency achieved by the proposed anti-jamming method in an IRS-assisted system. The optimal adjustment of the phase shifts in the IRS elements has resulted in a significant enhancement of about 25% in spectral efficiency compared to the random IRS phase case.