I couldn't decide whether to put this on ask science or ask historians so correct me if this is the wrong place to post it. I know people amputated to prevent gangrene but gangrene itself isn't a disease it's a symptom.
The answer is the same as today: bacteria that live on your skin. It's not like we have a substantially different bacteria population than our recent ancestors - the bacterial species have been evolving right along with us. Generally, you expect post-op infections from gram positive organisms like staph and strep species, though there may have been some gram negative bacteria like pseudomonas that can sometimes survive on the skin. But, for instance, it's routine surgical practice these days to give Ancef (plus or minus another agent depending on the surgery), generally within one hour prior to the incision. This significantly lower the incidence of surgical wound infections:
===========
A recent "meta-analysis of meta-analyses" involving 250 clinical trials and 4809 patients has provided an estimation of the relative benefit of systematic prophylactic antibiotics to reduce infection for 23 different types of surgery. The type of antibiotic, timing, dosing, and type of procedure varied widely in this analysis, but the relative risk of developing infection for all types of operations with prophylactic systemic antibiotics versus no prophylactic antibiotics varied from 0.19 to 0.82, suggesting a generalized benefit regardless of the degree of contamination.
(To add just a bit about how we talk about medical statistics, if the odds of infection were equal between the control and experimental group, the RR would be 1.0).
==============
Also, there are three broad categories of gangrene - wet, dry, and gas. Dry gangrene doesn't necessarily indicate an infectious process. You can get necrosis/death from poor blood flow (either poor arterial inflow or poor venous outflow) that leads to ischemia and tissue death. Wet gangrene is what you're thinking of - an infectious process leading to tissue death. Gas gangrene basically means you're screwed because you have an exotoxin forming species like clostridum that can lead to rapid multisystem organ failure and death. If it gets into an avascular space between the tissue planes, you end up getting necrotizing fasciitis (what is colloquially called "flesh eating bacteria" though many bacterial species can cause it).
==========
Source: above provided various links and medical school. Mods, if this answer isn't up to snuff, please feel free to delete this post. When I typed this up there weren't any replies yet.