We give an algorithm that computes the closest pair in a set of n points in k-dimensional space on-line, in O(nlogn) ime. The algorithm only uses algebraic functions and, therefore, is optimal. The algorithm maintains a hierarchical subdivision of k-space into hyperrectangles, which is stored in a binary tree. Centroids are used to maintain a balanced decomposition of this tree