Liver segmentation in medical images, particularly CT scans, is crucial for diagnosing and treating liver diseases. However, manual segmentation by radiologists is time-consuming and prone to errors, necessitating automated solutions. Although deep learning methods have shown promise, issues such as model overfitting, convergence, and sensitivity to noise persist. In response, this paper introduces GWO-SwinUNet, a novel liver segmentation framework that combines the Gray Wolf optimized Swin Transformer with the UNet architecture. By leveraging this hybrid approach, the method enhances fine-grained details while maintaining robustness and convergence speed. Extensive experimentation on diverse datasets and comparisons with state-of-the-art methods demonstrate the superior performance of GWO-SwinUNet, achieving a Dice coefficient of 0.988 and a Jaccard coefficient of 0.979. A thorough ablation study further validates the efficacy of the proposed strategy. In summary, GWO-SwinUNet represents a significant advancement in liver segmentation, harnessing the strengths of transformer-based architectures and optimization techniques to enhance accuracy and efficiency in medical image analysis.