Phosphorylation of the RNA polymerase II C-terminal domain (CTD) by cyclin-dependent kinases is important for productive transcription. Here we determine the crystal structure of Cdk12/CycK and analyse its requirements for substrate recognition. Active Cdk12/CycK is arranged in an open conformation similar to that of Cdk9/CycT but different from those of cell cycle kinases. Cdk12 contains a C-terminal extension that folds onto the N- and C-terminal lobes thereby contacting the ATP ribose. The interaction is mediated by an HE motif followed by a polybasic cluster that is conserved in transcriptional CDKs. Cdk12/CycK showed the highest activity on a CTD substrate prephosphorylated at position Ser7, whereas the common Lys7 substitution was not recognized. Flavopiridol is most potent towards Cdk12 but was still 10-fold more potent towards Cdk9. T-loop phosphorylation of Cdk12 required coexpression with a Cdk-activating kinase. These results suggest the regulation of Pol II elongation by a relay of transcriptionally active CTD kinases.