Peritonitis is primarily caused by an infection that spreads to the peritoneum, often due to perforation of the gastrointestinal tract, such as in appendicitis, diverticulitis, or peptic ulcer disease. Other causes include trauma to the abdomen, infections like tuberculosis or fungal infections, and even complications from peritoneal dialysis. An intra-abdominal abscess, which often accompanies peritonitis, is typically the result of localized infection following surgical procedures, perforated organs, or pancreatitis, leading to the accumulation of pus within the abdominal cavity.