Final answer:
The afferent component of the gag reflex is mediated by the glossopharyngeal nerve and the efferent component is mediated by the vagus nerve.
Step-by-step explanation:
The afferent (sensory) component of the gag reflex is mediated by the glossopharyngeal nerve. This nerve relays general sensations from the pharyngeal walls and can be stimulated by certain taste stimuli as well. The efferent (motor) component of the gag reflex is mediated by the vagus nerve, which directly stimulates the contraction of the muscles in the pharynx and larynx.