Despite all efforts to stay off shoals, beaches, or rocks, groundings do happen. It is said that there are only three kinds of skippers, those who have run aground, those who will run aground, and those that have but won't admit it. It is important that every boater be prepared for such an event with knowledge of what to do and the equipment with which to do it.
First, here is what you should not do when you run aground. Unless you are absolutely sure that it is a small shoal with deeper water ahead, do not apply power and try to push your way across, you will only put yourself harder aground. Do not immediately shift into reverse and increase engine power in an attempt to back off, you might suck up mud and/or bottom vegetation into the engine intake (watch for any signs of engine overheating), and you might further damage the propellers. Instead, take time to assess the situation. Is any water coming into the hull? Where exactly are you? How did you get there? Where might deeper water lie? What is the state of the tide?
If you have a dinghy in the water, or can launch one, use it to take soundings all around your boat. If you are in a rocky area, it is especially important not to attempt to refloat the craft immediately. First, check for any hull damage. The rocks you are on might be the only thing keeping your boat afloat! If the damage is considerable, set out an anchor or two to keep you in place for the time being. Even if you don't need any immediate assistance, you should radio the Coast Guard or other local authority. Advise them of your situation and your intended actions.
Let's assume that you are lucky and that the tide is rising and that the increased depths will be enough to float you free. Although you might get offsooner if another vessel pulled, letting the tide float you off is less stressful on your hull and your crew. It may be necessary to set out an anchor in the direction of the wind and waves to prevent the rising tide from carrying you further up on the shoal.
If you are less lucky, and the tide is falling, quickly assess the situation and the possibility of refioating the boat before the tide goes down further. If this is not possible, determine how far it will go down. Will the hull need cushioning and supports as it lays over on its side? While you wait for the tide or assistance, you might want to use the opportunity to inspect and clean your hull's bottom. (If you are quick on your feet you might even be able to convince others that that was why you went aground!)
If you are only lightly stranded, you may be able to get off without assistance. First, determine where deeper water lies, this may or may not be the direction from which you came. Then, try to reduce draft. In any type of craft, sail or power, you can empty water tanks if the supply isn't critical. You might also place some heavy gear in a dinghy. On a sailboat, you can try reducing draft by taking a halyard out to one side, attaching it to an anchor or another boat, and pulling.
Yet another maneuver is to put out an anchor in the direction in which you wish to move. If you have an anchor windlass or a sheet winch, use that to take in the line. This is called "kedging off." The anchor can be carried out by dinghy (with the line in the dinghy being paid out as it moves away from the vessel). If this isn't possible, the anchor can be supported on PFDs or buoyant cushions and floated out to where it is to be set, the longer the scope, the better. If another boat is available to help you, run a line to that boat if it can pull in the desired direction. Be very careful that the other boat does not become stranded in the same shallow water. It may be necessary for the other boat to put out an anchor to keep her clear. Be sure that both boats have deck fittings that can withstand the strain of the pull. Typical recreational boats may not have such hardware. If a pull is made, keep all persons away from the line and beyond the ends of the line in both directions. Various types of lines stretch to different degrees, but all stretch enough to act as slingshots if they break or if fittings pull out. Serious injury, or even death, are possible results of such failures. Even if the other boat cannot pull to get you off, she may help by running back and forth and making as large a wake as possible. The waves formed in this wake may lift your boat enough to get her off. You should use this technique only where the bottom is soft enough to cushion your underbody. A sandy bottom would probably be okay, but you don't want to be heaving up and down on rock.
I would encourage any boater to join one of the commercial towing organizations. However, you should check with other boaters in your area for recommendations as to which one to join. Ask what kind of service they have received from the company. Trust me, they are not all created equal.