Sequences and structures of all P-loop-fold proteins were compared with the aim of reconstructing the principal events in the evolution of P-loop-containing kinases. It is shown that kinases and some related proteins comprise a monophyletic assemblage within the P-loop NTPase fold. An evolutionary classification of these proteins was developed using standard phylogenetic methods, analysis of shared sequence and structural signatures, and similarity-based clustering. This analysis resulted in the identification of approximately 40 distinct protein families within the P-loop kinase class. Most of these enzymes phosphorylate nucleosides and nucleotides, as well as sugars, coenzyme precursors, adenosine 5'-phosphosulfate and polynucleotides. In addition, the class includes sulfotransferases, amide bond ligases, pyrimidine and dihydrofolate reductases, and several other families of enzymes that have acquired new catalytic capabilities distinct from the ancestral kinase reaction. Our reconstruction of the early history of the P-loop NTPase fold includes the initial split into the common ancestor of the kinase and the GTPase classes, and the common ancestor of ATPases. This was followed by the divergence of the kinases, which primarily phosphorylated nucleoside monophosphates (NMP), but could have had broader specificity. We provide evidence for the presence of at least two to four distinct P-loop kinases, including distinct forms specific for dNMP and rNMP, and related enzymes in the last universal common ancestor of all extant life forms. Subsequent evolution of kinases seems to have been dominated by the emergence of new bacterial and, to a lesser extent, archaeal families. Some of these enzymes retained their kinase activity but evolved new substrate specificities, whereas others acquired new activities, such as sulfate transfer and reduction. Eukaryotes appear to have acquired most of their kinases via horizontal gene transfer from Bacteria, partly from the mitochondrial and chloroplast endosymbionts and partly at later stages of evolution. A distinct superfamily of kinases, which we designated DxTN after its sequence signature, appears to have evolved in selfish replicons, such as bacteriophages, and was subsequently widely recruited by eukaryotes for multiple functions related to nucleic acid processing and general metabolism. In the course of this analysis, several previously undetected groups of predicted kinases were identified, including widespread archaeo-eukaryotic and archaeal families. The results could serve as a framework for systematic experimental characterization of new biochemical and biological functions of kinases.