The away match victory gives the Swiss side three points in Group E, tied with Estonia and Slovenia, but behind leaders England and Lithuania each with six points.
San Marino remains winless.
Switzerland, which earlier lost to England and Slovenia, opened the scoring on Tuesday with a goal from forward Haris Steforic after ten minutes.
Steforic scored again 14 minutes later.
Midfielder Blerim Dzemali notched the third goal at the 30-minute mark and Xherdan Shaqiri scored again in the 79th minute.
Switzerland missed an opportunity to pot another goal in the final minute when Ricardo Rodriguez’s penalty shot was saved by San Marino’s goalie Aldo Simoncelli.
The Swiss will face a sterner test in a month’s time against Lithuania in its next Euro qualifying match.