The Sharks will take their 3-1 series lead back home with a chance to advance on Sunday night to the NHL's final four.
Detroit is trying to become the fourth NHL team to win a series after trailing 3-0.
Veteran defenseman Nicklas Lidstrom scored twice in the first period to help the Red Wings take a three-goal lead that they let slip away.
Logan Couture had a goal 15 seconds after Lidstrom's second, Dan Boyle scored midway through the middle period to pull San Jose within 3-2, and Dany Heatley tied it early in the third.
BRUINS 5, FLYERS 1
In Boston, Milan Lucic scored twice, Johnny Boychuk got the go-ahead goal, and Boston stopped any chance of another historic comeback by Philadelphia, completing a sweep of the Eastern Conference semifinal series.
Kris Versteeg lifted Philadelphia into a 1-1 tie on at 13:22 of the second period after Lucic scored at 12:02 of the first. Boychuk put Boston ahead at 2:42 of the third, Lucic connected again at 15:03, and Brad Marchand and Daniel Paille added empty-net goals.
The Bruins are in the conference finals for the first time since 1992 and will have home-ice advantage against the Tampa Bay Lightning.
Philadelphia was swept 4-0 for the first time since losing to Detroit in the 1997 Stanley Cup finals.
Boston has won seven of eight games and is aiming for its first Stanley Cup title since 1972.