Population structure is a key determinant in fostering cooperation among naturally self-interested individuals in microbial populations, social insect groups, and human societies. Traditional research has focused on static structures, and yet most real interactions are finite in duration and changing in time, forming a temporal network. This raises the question of whether cooperation can emerge and persist despite an intrinsically fragmented population structure. Here we develop a framework to study the evolution of cooperation on temporal networks. Surprisingly, we find that network temporality actually enhances the evolution of cooperation relative to comparable static networks, despite the fact that bursty interaction patterns generally impede cooperation. We resolve this tension by proposing a measure to quantify the amount of temporality in a network, revealing an intermediate level that maximally boosts cooperation. Our results open a new avenue for investigating the evolution of cooperation and other emergent behaviours in more realistic structured populations.