SAN JOSE, Calif. -- A familiar pattern unfolded Saturday night in Game 5 of the Western Conference semifinals: The Detroit Red Wings kept the game close, but found a way to lose it late.

Patrick Marleau snapped a tie at 6:59 of the third period, as the San Jose Sharks eliminated the Red Wings from the playoffs with a 2-1 victory at the HP Pavilion.

After reaching the Stanley Cup finals in each of the last two seasons, the Red Wings were ousted in the second round after losing four one-goal games

“It’s tough when you fall short of your goal, especially in a series like this, where you felt you were in this series even though we were down 3-0 (in games),’’ Detroit captain Nicklas Lidstrom said. “Even in this game going into the third period we felt we had a chance to win the game but just couldn’t get it done.’’

The Red Wings could not build off the momentum from their 7-1 victory in Game 4.

“They won four games to one, so they were better than us,’’ Red Wings coach Mike Babcock said. “I thought Game 2 was a big loss. We had a (2-1) lead and got into big penalty trouble. The games were tight, but they found a way to continue to win. That’s what good teams do.’’

The Sharks reached the conference finals for only the second time in franchise history. They will face the winner of the series between Chicago and Vancouver, which the Blackhawks lead 3-1.

“It’s frustrating because they didn’t hold the lead once going into the third period and still found a way to win,’’ said Red Wings defenseman Brad Stuart, who played this game with a sprained right medial collateral ligament. “We had ample opportunity to win those games. It’s a fine line this time of year. We just found ourselves on the wrong side of it too many times.’’

Sharks goaltender Evgeni Nabokov rebounded from his disastrous performance in Game 4 by making 33 saves.

Marleau was wide open in the slot when he one-timed a pass from Joe Thornton past Jimmy Howard on the glove side. Brian Rafalski was checked behind the net, leading to a giveaway, on which the Sharks quickly capitalized.

“I didn’t have a lot of time and I was thinking everyone was still on that side,’’ Rafalski said. “Obviously, we didn’t give ourselves a very big margin for error. It seems it was like that the whole series.’’

Just prior to the goal, Douglas Murray leveled Johan Franzen with a blindside check to the head with his shoulder. Franzen was down while play continued. The Red Wings felt it warranted a penalty. Instead, it resulted in a faceoff in the Detroit zone, which led to the winning goal.

“That’s the way it goes,’’ Babcock said. “To me, those are little events that take place in games but aren’t about the series.’’

The Red Wings had a six-on-four advantage with 52 seconds remaining in the third period after Dan Boyle was penalized for holding and Detroit pulled Howard for the extra skater. But the Red Wings failed to get a shot on goal.

“You’re just trying to get the puck in there,’’ Lidstrom said. “They’re doing a good job being in lanes, almost leaving our guys by themselves in front. It was hard to get the shots through.’’

Sharks center Joe Pavelski shot high and wide on a penalty shot at 3:12 of the third period, with the game tied at 1-1. He was awarded the penalty shot after beating Niklas Kronwall one-on-one to break in alone on Howard and getting hooked by the Detroit defenseman.

After being outplayed in the scoreless first period, the Red Wings dominated the second period, outshooting the Sharks 14-3. But each team scored once. Detroit had three power plays but couldn’t convert.

“Couple mistakes here and there, not executing or capitalizing on our power play when we had opportunities,’’ Lidstrom said. “I thought that was the difference in this series.’’

Stuart returned to action after leaving Game 4 early in the first period due to his knee injury. Babcock dressed seven defensemen, inserting Brett Lebda for forward Mattias Ritola, just in case Stuart reaggravated his injury.

Rafalski opened the scoring at 2:40 on a blast from the point that beat deflected in off the stick of the stick of Marleau in the slot, while Todd Bertuzzi was parked in front of Nabokov. Bertuzzi checked Murray behind the net, which forced the turnover that created the scoring chance.

Thornton came back to tie on the power play at 4:54, after Stuart was whistled for elbowing, Detroit’s third consecutive penalty.

Thornton won a faceoff from Pavel Datsyuk and then went to the net and calmly deposited the rebound of a blast by Jason Demers past Howard.

Howard made several big stops in the first period, when the Sharks, sparked by a pair of power plays, outshot Detroit 15-6.

“Right now it’s a bitter bill to swallow,’’ Babcock said. “Once we got through the first period I thought we’d win for sure.’’

“Their team played hard, their good players were really good and their goalie was excellent. Todd (Sharks coach McLellan) and his group had them well-prepared.’’

Said Red Wings center Henrik Zetterberg: “They won fair and square, they were the first to four, they got the job done and we didn’t. You can say we were real close in every game, but it doesn’t matter.’’