A stochastic Gronwall inequality and its applications