It's called "panning". You do the same thing with a video camera, except when you take photos at a low enough shutter speed, you get that sort of background. However, if you point the camera so that it follows the motion of the car, the car is still in focus. In other words, point your camera at the car as it moves from your right side, to your left (just like in the photo). You need to follow the car, or "pan with the car" perfectly to ensure that the car is perfectly in focus. If you have a DSLR, then just focus on the side mirror, driver side window or something as it moves from right to left. Continue panning while you take the photo.
Actually, as long as one thing in the image isn't movie (relative to your camera), while another part of your image (eg: the background) IS moving relative to the camera, you'll get this blur.
I'll show you. This shot has the motion blur you're talking about at the sides, and yet the train itself is perfectly in focus. I'm not moving with respect to the train, but all the trees and stuff outside the train are moving, since the train was moving.