The answer is pretty simple, general anesthesia paralyzes the body and renders the patient unconscious. When I say paralyze, I mean the vast majority of the muscles in the body are unable to move. The heart is one exception, as it will continue to beat on its own throughout the surgery, but the diaphragm, the muscle that makes it possible to fill the lungs with air, is unable to move. If the muscles that help fill the lungs can't move, then you are unable to breathe.
If you have ever gotten the "wind knocked out of you" and have that scary feeling of not being able to take a breath, then you've experience a very brief paralysis of the diaphragm muscles.
So, to make surgery possible, the lungs have to be filled with air so they can do their job. This is accomplished by putting a tube, called an endotracheal tube, into the mouth and down into the airway of the patient, a process called intubation. The end of the tube that is left outside of the mouth is connected to a ventilator, which provides breaths to the lungs. The lungs continue to function normally, but the ventilator does the work of the paralyzed muscles.
Once the surgery is over and the anesthesia has worn off, the tube is removed and the muscles of the body return to their normal function. In some cases, patients may need more time until they are ready to breathe on their own, but in most cases, you can expect to be breathing on your own before you leave the operating room.