There are very few instances in which positive Darwinian selection has been convincingly demonstrated at the molecular level. In this study, we present a novel test for detecting positive selection at the amino-acid level. In this test, amino-acid replacements are characterized in terms of chemical distances, i.e., degrees of dissimilarity between the exchanged residues in a protein. The test identifies statistically significant deviations of the mean observed chemical distance from its expectation, either along a phylogenetic lineage or across a subtree. The mean observed distance is calculated as the average chemical distance over all possible ancestral sequence reconstructions, weighted by their likelihood. Our method substantially improves over previous approaches by taking into account the stochastic process, tree phylogeny, among site rate variation, and alternative ancestral reconstructions. We provide a linear time algorithm for applying this test to all branches and all subt...