Fluctuations in the shallow groundwater table change the biochemical environment and nitrogen cycling processes along the soil profile and cause the loss of nitrogen from the soil profile and nitrogen pollution in shallow groundwater. With a microcosm experiment, this study aimed to examine the effects of variations in soil properties caused by water table fluctuations on the bacterial communities and the nitrogen transformation functional genes along the soil profile in a vegetable field. The results showed that Proteobacteria and Acidobacteria were the dominant phyla in the samples. With the lowering of the water table and continuous drying of the soil profile, the abundances of the narG, nirK, nirS and nosZ genes gradually decreased, and the abundances of the AOA-amoA and AOB-amoA genes gradually increased. The functional genes gradually decreased with increasing soil depth. Water table fluctuations had obvious effects on the bacterial communities in the C and D layers, but the soil physicochemical properties had greater impacts in the A and B layers. The soil water content (W), TN, TOC, NH4+-N, pH and NO3−-N were significantly related to the soil bacterial communities. The two key functional gene groups directly driving the major processes for NH4+-N and NO3--N transformation were nosZ/narG and nosZ/(nirK+nirS). This study provides insights into the relative importance of variations in soil properties and the microbial community in the soil profile caused by water table fluctuations in driving the transformation of soil nitrogen.