Run depth-first search and put each vertex on the front of a list as it finishes: the list comes out in topological order, unless a back edge shows a cycle.
This interactive visualization needs JavaScript.