Surgical masks are widely used for infectious source control by preventing infected individuals from transmitting pathogens. However, poor fit can create gaps between the mask and face, reducing their effectiveness. In this study, a numerical model was developed based on realistic surgical mask geometry with peripheral gaps of varying sizes and positions, fitted onto a breathing manikin. Exhalation leakage airflow dynamics and aerosol pathogen dispersion were investigated using a validated computational fluid dynamics (CFD) model with porous media. Results indicate that despite the presence of leaks, surgical masks are effective in controlling the spread of pathogens, with maximum airflow leakage at 9.11% and pathogen leakage at 16.83%. The average velocity of leaked airflow ranged from 0.12 m/s to 1.43 m/s, depending on the gap size and position. The position of the gap had little impact on the airflow and pathogen leakage fractions. Correlations between the average velocity of net leakage flow, leakage fractions of airflow and pathogens, and gap size were developed. Pathogens spread most widely from bottom leaks, followed by side and top leaks, with bottom leaks releasing up to 9.7 times more contaminated air than top leaks and 6.5 times more than side leaks. The findings also suggest that smaller gaps are associated with higher initial velocities of leakage, which in turn lead to wider dispersion of pathogens.