the chemical potential
Heat flows from hot to cold until temperatures match; volume shifts from high pressure to low until pressures match. There is a third such 'driving' quantity that governs the flow of particles — the chemical potential. It measures the energy price of adding one more particle to a system, and particles migrate from where mu is high to where mu is low until the two equalize. Think of it as a 'particle pressure'.
Precisely, the chemical potential of species i is the change in a potential when you add one particle of that species while holding the appropriate variables fixed: mu_i = (dU/dN_i)_{S,V,N_j} = (dG/dN_i)_{T,p,N_j} = (dF/dN_i)_{T,V,N_j}. For a single pure substance it equals the molar (per-particle) Gibbs free energy, mu = G/N. Two systems (or two phases) in diffusive contact are in equilibrium when their temperatures, pressures and chemical potentials are all equal; a chemical reaction runs until sum nu_i mu_i = 0.
The chemical potential is the linchpin of open systems, phase coexistence and reactions, and it reappears in disguise as the Fermi level (electrochemical potential) of electrons in a solid, fixing where a semiconductor's electrons sit. A common misconception is that mu must be negative or must decrease with density in general — for interacting or quantum systems mu can be positive, and for fermions at low temperature it is large and positive (the Fermi energy).
Put two boxes of the same gas at the same temperature in contact through a small hole. If box A is denser, its chemical potential is higher (mu = k_B T ln(n lambda^3) for an ideal gas, rising with density n). Molecules therefore drift from A to B until the densities — and the chemical potentials — equalize.
Particles flow down a chemical-potential gradient, just as heat flows down a temperature gradient.
For a classical ideal gas mu is negative and grows more negative as density drops, but this sign is not universal: for a degenerate Fermi gas mu approaches the positive Fermi energy as T -> 0.