The opportunity attack action is an opportunity action available to all player characters, and is the most common opportunity action.
Triggering opportunity attacks is usually called provoking opportunity attacks. The opportunity attack action is provoked by an enemy leaving an adjacent square without shifting or teleporting, or by an adjacent enemy using a ranged or area power.[PHB:290] Like all opportunity actions, opportunity attacks cannot be provoked by forced movement.[PHB:285]
Like all opportunity actions, an opportunity attack interrupts the action that provoked it. The opportunity attack resolves before the interrupted action. If the interrupted action becomes impossible to complete, for example, if the opportunity attack reduces the enemy to 0 hit points, the interrupted action is lost.
A character can take any number of opportunity actions per round, but no more than one opportunity action during each other combatant's turn. A character cannot take opportunity actions, including opportunity attacks, during the character's own turn.[PHB:268]
Some creatures have an ability called threatening reach. This lets them make opportunity attacks against nonadjacent enemies. If an enemy leaves a square that's within the creature's reach, or if an enemy anywhere within the creature's reach makes a ranged attack or an area attack, the creature can make an opportunity attack against that enemy.
Combatants constantly watch for their enemies to drop their guard. When you're adjacent to an enemy, that enemy can't move past you or use a ranged power or an area power without putting itself in danger by allowing you to take an opportunity attack against it.