Among the consequences of the disordered interaction topology underlying many social, technological, and biological systems, a particularly important one is that some nodes, just because of their position in the network, may have a disproportionate effect on dynamical processes mediated by the complex interaction pattern. For example, the early adoption of a commercial product by an opinion leader in a social network may change its fate or just a few superspreaders may determine the virality of a meme in social media. Despite many recent efforts, the formulation of an accurate method to optimally identify influential nodes in complex network topologies remains an unsolved challenge. Here, we present the exact solution of the problem for the specific, but highly relevant, case of the susceptible-infected-removed (SIR) model for epidemic spreading at criticality. By exploiting the mapping between bond percolation and the static properties of the SIR model, we prove that the recently introduced nonbacktracking centrality is the optimal criterion for the identification of influential spreaders in locally tree-like networks at criticality. By means of simulations on synthetic networks and on a very extensive set of real-world networks, we show that the nonbacktracking centrality is a highly reliable metric to identify top influential spreaders also in generic graphs not embedded in space and for noncritical spreading.