Start by wetting your skin with a warm washcloth, or try shaving in the shower; the warm water will help open your pores, making the hair easier to remove and lowering your risk of cuts and nicks.
As always, be sure to use a clean, sharp blade and a shaving gel to keep your skin hydrated. Using slow, short strokes, move the razor across your skin. Shave in the direction of the hair growth, and avoid stroking the razor multiple times over one area. Be gentle, especially in the area of the blemish.
If you have an electric razor, use it rather than a manual razor while you have pimples.