A distance metric is a mathematical function used to quantify the similarity or dissimilarity between two data points in a given space, adhering to specific properties such as non-negativity, identity of indiscernibles, symmetry, and the triangle inequality. These metrics are crucial in various fields like machine learning, clustering, and optimization, where they help in tasks such as nearest neighbor search and data classification.