Quasi-biennial oscillations (QBO) are frequently observed in the solar activity indices. However, no clear physical mechanism for the observed variations has been suggested so far. Here we study the stability of magnetic Rossby waves in the solar tachocline using the shallow water magnetohydrodynamic approximation. Our analysis shows that the combination of typical differential rotation and a toroidal magnetic field with a strength > 10^5 G triggers the instability of the m=1 magnetic Rossby wave harmonic with a period of 2 years. This harmonic is antisymmetric with respect to the equator and its period (and growth rate) depends on the differential rotation parameters and the magnetic field strength. The oscillations may cause a periodic magnetic flux emergence at the solar surface and consequently may lead to the observed QBO in the solar activity features. The period of QBO may change throughout the cycle, and from cycle to cycle, due to variations of the mean magnetic field and differential rotation in the tachocline.