The effect of environmental fluctuations is a major question in ecology. While it is widely accepted that fluctuations and other types of disturbances can increase biodiversity, there are fewer examples of other types of outcomes in a fluctuating environment. Here we explore this question with laboratory microcosms, using cocultures of two bacterial species, P. putida and P. veronii. At low dilution rates we observe competitive exclusion of P. veronii, whereas at high dilution rates we observe competitive exclusion of P. putida. When the dilution rate alternates between high and low, we do not observe coexistence between the species, but rather alternative stable states, in which only one species survives and initial species' fractions determine the identity of the surviving species. The Lotka-Volterra model with a fluctuating mortality rate predicts that this outcome is independent of the timing of the fluctuations, and that the time-averaged mortality would also lead to alternative stable states, a prediction that we confirm experimentally. Other pairs of species can coexist in a fluctuating environment, and again consistent with the model we observe coexistence in the time-averaged dilution rate. We find a similar time-averaging result holds in a three-species community, highlighting that simple linear models can in some cases provide powerful insight into how communities will respond to environmental fluctuations.