Expansions of short nucleotide repeats produce several neurological and neuromuscular disorders including Huntington disease, muscular dystrophy, and amyotrophic lateral sclerosis. A common pathological feature of these diseases is the accumulation of the repeat-containing transcripts into aberrant foci in the nucleus. RNA foci, as well as the disease symptoms, only manifest above a critical number of nucleotide repeats, but the molecular mechanism governing foci formation above this characteristic threshold remains unresolved. Here we show that repeat expansions create templates for multivalent base-pairing, which causes purified RNA to undergo a sol–gel transition in vitro at a similar critical repeat number as observed in the diseases. In human cells, RNA foci form by phase separation of the repeat-containing RNA and can be dissolved by agents that disrupt RNA gelation in vitro. Analogous to protein aggregation disorders, our results suggest that the sequence-specific gelation of RNAs could be a contributing factor to neurological disease. Nucleotide repeat expansions create templates for multivalent base-pairing, which causes RNA to undergo a sol–gel phase transition and may explain the formation of nuclear RNA foci that are commonly observed in several neurological and neuromuscular diseases. Expansion in the length of certain trinucleotide sequences underlies several neurological diseases. The lengthened repeats are thought to make the RNA transcripts 'toxic', and at disease-associated lengths these RNAs form foci. Ankur Jain and Ron Vale find that the reason foci formation requires a particular length repeat is because at the disease length, the RNA undergoes a phase separation. This suggests that, similar to neurological diseases caused by protein aggregation, the gelation of RNAs may contribute to the pathology of trinucleotide-repeat diseases.