The stability of pipe flow when mildly deviating from the developed Poiseuille profile by a non-axisymmetric azimuthally periodic distortion is examined. The motivation for this is to consider deviations, the origin of which may be attributed to small-amplitude disturbances having sinusoidal periodicity along the azimuthal coordinate, which are known to be the ones most amplified by the transient growth linear mechanism. A mathematical technique for finding the minimum energy density of azimuthally periodic deviations triggering exponential instability is presented. The results show that owing to bifurcations multiple solutions of optimal deviations exist. As the Reynolds number is increased additional bifurcations appear and create more distinct solutions. The different solutions correspond to different radial distributions of the deviations, and at Reynolds numbers of about 2000 they are distributed over less than a half of the pipe radius. It is found that the dependence of the optimal deviation velocity leading to instability on the Reynolds number Re is approximately 20/Re. A comparison to axisymmetric base-flow deviations shows that the minimum energy required for an azimuthally periodic deviation to trigger instability is almost twice that for the axisymmetric flow. However, azimuthally periodic deviations, which are shown to have a streaky pattern, may have a role in the self-sustaining process. They may be formed as a result of a transient growth amplification of initial streamwise rolls and can produce, via self-interactions between the resulting growing waves, patterns of streamwise rolls as well.