Emergency services were called to Richmond Avenue in Ferrybridge at around 12.50pm on Saturday.
The Pontefract and Knottingley Neighbourhood Police Team (NPT) said a vehicle had collided with a property, causing a gas main to burst.
Road closures were put in place and a crew from Pontefract Fire Station set up cordons and evacuated people from nearby premises.
John Lloyd, West Yorkshire Fire Service's assistant district commander for Wakefield, said gas was leaking into the building and around the surrounding areas.
He said the team took tiles off the roof and smashed windows to let gas escape, fearing there could have been an explosion.
Wakefield Council, Yorkshire Ambulance Service Hazardous Area Response Team (HART) and Northern Gas also attended, and the gas supply was secured and the pipe repaired.
Officers from the Pontefract and Knottingley NPT thanked St Andrew's Church in Ferrybridge for showing "great community spirit" and opening its doors to those evacuated.
The church provided hot drinks and a place for people to shelter from the cold.
No one was injured in the incident, which police said was being filmed as it unfolded, by a crew accompanying HART, for television.