They use reaction wheels, which are a type of flywheel to stabilize many spacecraft. For missions that need to be extremely stable (i.e., any mission with telescopes like Hubble), they try to avoid using the thrusters as these cause small vibrations to "ring" throughout the spacecraft. The vibrations can last for relatively long periods of time on some spacecraft due to their design.
Edit
I should add that reaction wheels are generally made of ferromagnetic (or slightly magnetic) materials for various reasons. Unfortunately, this causes a lot of problems for a spacecraft that needs to measure electromagnetic fields, as a rotating magnetic produces huge fields compared to, say, the solar wind. Hubble, thankfully, only cares about incident light which really should not care about the small fields produced by these wheels. The new mission, Solar Probe Plus, does care about magnetic cleanliness so they are working on dealing with the induced fields from the reaction wheels.
Edit: 2
For small spacecraft, for instance CubeSats, that do not care about absolute precision in their attitude control, they can use magnetic torque from the Earth's magnetic field to align an axis of a large magnet within the spacecraft body. This can be useful for CubeSats that have a particle detector that wishes to remain looking along the background magnetic field.
Some spacecraft, like Wind, have star sensors in addition to a sun sensor. These systems are used to help maintain the desired pointing direction of a spacecraft. In the case of Wind, the flight operations team use the star and sun sensors to keep the spin axis within $<$ $1^{\circ}$ of the south ecliptic pole. The angular momentum supplied by the long wire antenna help to maintain a very stable pointing axis.
Edit: 3
@PaulEGCopeBScARCSFBIS made a useful suggestion regarding the EXOSAT mission, which used a combination of gyros and thrusters to refine its attitude control. The following from White and Peacock, [1988] summarizes the spacecraft's capabilities:
A propane cold-gas thruster system was used for both slew manoeuvres and fine pointing. The attitude was controlled using one of two star trackers (with each attached to a low energy telescope), three gyros and a sun sensor and could be maintained to within ~1 arc second. The star trackers required at least one star (but preferably two for the most accurate attitude reconstruction) brighter than eighth magnitude within its 3° square field of view.
So as Paul mentioned, I should not have dismissed thruster controls so quickly. The downside with thrusters is that it limits their lifespan and can introduce a cloud of neutral particles, which quickly ionize, and can corrupt particle and fields measurements.
References
White, N.E. and A. Peacock "The EXOSAT observatory," Mem. S. A. It. 59, pp. 7-31, 1988.