Bacterial swarming is one of the most efficient methods by which bacteria colonize nutrient-rich environments and host tissues. Several mechanisms have been proposed to explain the phenomenon and the associated intricate macroscopic pattern formation, but so far no conclusive evidence has been presented that identifies the factors that control swarming. Vice versa, little is known about how swarming can be controlled. Here, by using a series of complementary genetic and physicochemical experiments and a simple mathematical analysis, we show how the bacterial swarming can be caused by a surface tension driven flow. The opportunistic pathogen, Pseudomonas aeruginosa, is studied, as it is relevant for such bacteria to control and arrest swarming. Moreover, P. aeruginosa bacteria secrete strong surface active components as part of their quorum sensing system. Our results demonstrate that surface tension gradient control can even be the dominant mechanism that drives swarming. It can be quantitatively predicted and can be expected to play a role in a wide variety of bacterial systems. The modeling reveals subtle dependencies on both the wetting conditions and the physical properties of the slime. Based on these dependencies, strategies can be devised to arrest swarming under certain conditions by simple physicochemical means.