The first law tells us energy is conserved, but it does not tell us which way a change will go on its own. A spontaneous process is one that occurs without continuous outside help (heat flowing from hot to cold, a gas expanding into vacuum). Many spontaneous reactions are exothermic, but exothermicity alone is not the criterion — ice melting above 0°C and ammonium nitrate dissolving are both spontaneous yet endothermic. A second factor is at work: disorder.
Entropy $S$ measures the disorder or the number of microscopic ways a system can be arranged. It is a state function. For a reversible process at temperature $T$, the entropy change is $\Delta S=\dfrac{q_{rev}}{T}$, with units $\text{J K}^{-1}\text{mol}^{-1}$. Entropy increases when solids melt, liquids vaporise, gases expand, or the number of gaseous molecules rises in a reaction.
The second law of thermodynamics states that for any spontaneous process the total entropy of the universe increases:
$\Delta S_{total}=\Delta S_{system}+\Delta S_{surroundings}>0$
At equilibrium $\Delta S_{total}=0$. Because tracking the surroundings is awkward, J. W. Gibbs combined enthalpy and entropy into a single system property, the Gibbs energy $G=H-TS$. At constant temperature and pressure its change is
$\Delta G=\Delta H-T\Delta S$
The Gibbs energy is the master criterion for spontaneity at constant $T$ and $P$: if $\Delta G<0$ the process is spontaneous (feasible); if $\Delta G=0$ the system is at equilibrium; if $\Delta G>0$ the process is non-spontaneous (the reverse is spontaneous). The magnitude $-\Delta G$ equals the maximum useful (non-expansion) work obtainable.
The interplay of the two terms decides the outcome. When $\Delta H<0$ and $\Delta S>0$, $\Delta G$ is negative at all temperatures (always spontaneous). When $\Delta H>0$ and $\Delta S<0$, $\Delta G$ is positive at all temperatures (never spontaneous). The remaining two cases are temperature-dependent: an endothermic reaction with $\Delta S>0$ becomes spontaneous only above $T=\Delta H/\Delta S$, while an exothermic reaction with $\Delta S<0$ is spontaneous only below that temperature.
Gibbs energy also connects thermodynamics to chemical equilibrium. The standard Gibbs energy change is related to the equilibrium constant $K$ by
$\Delta G^\circ=-RT\ln K$
A large negative $\Delta G^\circ$ means $K\gg1$ (products favoured); a positive $\Delta G^\circ$ means $K<1$ (reactants favoured). At equilibrium $\Delta G=0$ even though $\Delta G^\circ$ need not be zero.
Finally, the third law of thermodynamics states that the entropy of a perfect crystalline substance is zero at absolute zero ($0$ K). This gives entropy an absolute reference point, so unlike $U$ and $H$ we can tabulate absolute standard entropies $S^\circ$ and use them to compute $\Delta_r S^\circ=\sum\nu_p S^\circ(\text{products})-\sum\nu_r S^\circ(\text{reactants})$.