We consider the set of points visited by the random walk on the discrete torus (\mathbb{Z}/N\mathbb{Z})^d, for d \geq 3, at times of order uN^d, for a parameter u>0 in the large-N limit. We prove that the vacant set left by the walk undergoes a phase transition across a non-degenerate critical value u_* = u_*(d), as follows. For all u< u_*, the vacant set contains a giant connected component with high probability, which has a non-vanishing asymptotic density and satisfies a certain local uniqueness property. In stark contrast, for all u> u_* the vacant set scatters into tiny connected components. Our results further imply that the threshold u_* precisely equals the critical value, introduced by Sznitman in arXiv:0704.2560, which characterizes the percolation transition of the corresponding local limit, the vacant set of random interlacements on \mathbb{Z}^d. Our findings also yield the analogous infinite-volume result, i.e. the long purported equality of three critical parameters \bar u, u_* and u_{**} naturally associated to the vacant set of random interlacements.