On the structure of the Selberg class, III: Sarnak's rigidity conjecture