The relative cost of owning versus renting is swinging back in favor of homeownership in some U.S. markets, buoyed by several quarters of sharp declines in home prices.

At the height of the housing boom, as home prices surged, demand for rentals started to rise as the gap between owning and renting widened significantly. Even after the housing market soured, apartment demand grew as former homeowners became renters, allowing landlords to push healthy rent increases.

Now,...