Clear everything off the shelf.
Find where the shelf attaches to the wall. In some cases, this will be hidden by a small wooden plug or nub. In nearly all cases, the attachment itself will involve screws.
Remove plugs as necessary by jimmying them out using your putty knife and flat-bladed screwdriver.
Remove any unattached components such as shelf boards that haven't been screwed to the shelf.
Unscrew and remove any components screwed to the shelf support, but not to the wall. The point of this step is to make the shelf as light as possible when you do detach it from the wall.
Unscrew all but one screw from each bracket that's attached to the wall.
Unscrew the final screw from any center brackets, if your shelf has more than two brackets.
Select one end bracket to unscrew. Brace it so that it won't fall when unscrewed. The simplest way to do this is to have an assistant hold it up.
Unscrew the final bracket, then set the shelf aside.
Fill all holes in your wall with joint compound, then allow them to dry. If the shelf used any drywall anchors, remove them prior to completing this step.
Paint over the filled holes with paint that matches the original wall color.