We consider a model for γ-ray production in blazars in which a relativistic, highly collimated electron-proton beam interacts with a dense, compact cloud as the jet propagates through the broad- and perhaps narrow-line regions of active galactic nuclei. During the propagation of the beam through the cloud, the process of excitation of plasma waves becomes an important energy-loss mechanism, especially for mildly relativistic proton beams. We compute the expected spectra of γ-rays from the decay of neutral pions produced in hadronic collisions of the beam with the cloud, taking into account collisionless losses of the electron-proton beam. This model may explain the X-ray and TeV γ-ray (both low and high emission states) of Mrk 421 as a result of synchrotron emission of secondary pairs from the decay of charged pions and γ-ray emission from the decay of neutral pions for the plausible cloud parameters. However, clouds cannot be too hot and too dense. Otherwise, the TeV γ-rays can be attenuated by the bremsstrahlung radiation in the cloud and the secondary pairs are not able to efficiently produce synchrotron flares because of the dominant role of inverse Compton scattering. The nonvariable γ-ray emission observed from Mrk 421 in the EGRET energy range cannot be described by the γ-rays from decay of neutral pions provided that the spectrum of protons in the beam is well described by a simple power law. These γ-rays might only be produced by secondary pairs scattering the soft nonvariable X-rays, which might originate in the inner part of the accretion disk.