In a perfectly competitive market, in case of shortage or surplus, buyers and sellers will self-regulate. These market forces will push the market towards the market clearing price (or equilibrium price) and market clearing quantity (or equilibrium quantity).
This is the law of Supply and Demand or the "Invisible Hand of the Market" as called by Adam Smith.