An abstract three critical points theorem and applications