An optical fiber scanner is used for multiphoton excitation imaging, optical coherence tomography, or for confocal imaging in which transverse scans are carried out at a plurality of successively different depths within tissue. The optical fiber scanner is implemented as a scanning endoscope using a cantilevered optical fiber that is driven into resonance or near resonance by an actuator. The actuator is energized with drive signals that cause the optical fiber to scan in a desired pattern at successively different depths as the depth of the focal point is changed. Various techniques can be employed for depth focus tracking at a rate that is much slower than the transverse scanning carried out by the vibrating optical fiber. The optical fiber scanner can be used for confocal imaging, multiphoton fluorescence imaging, nonlinear harmonic generation imaging, or in an OCT system that includes a phase or frequency modulator and delay line.