The nature of ultracompact H II regions (UCHRs) remains poorly determined. In particular, they are about an order of magnitude more common than would be expected if they formed around young massive stars and lasted for one dynamical time, around 10^4 yr. We here perform three-dimensional numerical simulations of the expansion of an H II region into self-gravitating, radiatively cooled gas, both with and without supersonic turbulent flows. In the laminar case, we find that H II region expansion in a collapsing core produces nearly spherical shells, even if the ionizing source is off-center in the core. This agrees with analytic models of blast waves in power-law media. In the turbulent case, we find that the H II region does not disrupt the central collapsing region, but rather sweeps up a shell of gas in which further collapse occurs. Although this does not constitute triggering, as the swept-up gas would eventually have collapsed anyway, it does expose the collapsing regions to ionizing radiation. We suggest that these regions of secondary collapse, which will not all themselves form massive stars, may form the bulk of observed UCHRs. As the larger shell will take over 10^5 years to complete its evolution, this could solve the timescale problem. Our suggestion is supported by the ubiquitous observation of more diffuse emission surrounding UCHRs.