SANTA CLARA, Calif. -- Anquan Boldin and Torrey Smith know a little bit about Baltimore's defense and how the Ravens take their chances going 1-on-1 outside.
They also know their share about Shareece Wright, a San Francisco teammate less than two weeks ago.
Boldin and Smith took it to the team they helped win the Super Bowl nearly three years ago, while Wright's embarrassing outing helped out his former 49ers on a day Baltimore missed chances in every phase in a 25-20 loss to San Francisco on Sunday.
"When you have a guy on your team for that long and get to see him every day in practice, you understand his weaknesses, as well as his strengths," Boldin said. "That was one of the things that we wanted to attack."
Colin Kaepernick completed a 76-yard touchdown pass to Smith, Joe Flacco threw two interceptions and the Niners stopped a four-game losing streak.
Phil Dawson kicked four field goals, including a 53-yarder, in the first win since Week 1 for San Francisco (2-4). Boldin - a Super Bowl star for the Ravens against San Francisco following the 2012 season - had a late 51-yard catch that set up Quinton Patton's 21-yard reception for the first touchdown of his career.
Flacco's desperation pass to the end zone on the final play went incomplete to Steve Smith, and the quarterback wound up 33 of 53 for 343 yards. Smith dropped two balls in the end zone before catching one.
Not only did the Ravens fail to pounce on Jarryd Hayne's fumbled punt return, kicker Justin Tucker shanked a 45-yard field goal off the right upright after he awkwardly slipped on the turf.
Kaepernick went 16 of 27 for 340 yards, and Boldin made five catches for 102 yards. Torrey Smith had three receptions for 96 yards.
The rematch of the Super Bowl three seasons ago featured a pair of last-place teams trying to turn around their seasons, and it showed in some sloppy play.
Steve Smith caught a 34-yard TD pass in the third, but the Ravens (1-5) are reeling through the worst start in franchise history. Tough weekend for the Harbaugh brothers after Baltimore coach John Harbaugh's little brother Jim's Michigan team lost Saturday to Michigan State on a botched punt.
The 49ers won for the first time since Sept. 14 against Minnesota.
Now San Francisco must prepare in a hurry for a short week with rival Seattle coming to town Thursday night. The Seahawks have won five of the last six meetings, including the playoffs.
Kaepernick is sensing a shift.
"We're a 2-4 football team that needs to get some more wins," he said. "Our team is building where we're gradually picking up momentum."
Baltimore's previous four losses featured second-half collapses. This time, it all but began from the opening kickoff.
The Ravens appeared a step behind all day. Their problems came in pairs, too: Steve Smith's two end-zone drops, two drops by the defense on would-be interceptions and Flacco's two picks.
"I don't have the frustration gauge out. I don't get frustrated. I don't get down, just disappointed," Harbaugh said. "I get determined is what I get. We have a bunch of guys that feel the same way. We have to get it done, and it starts with me."
Wright, released by the 49ers on Oct. 10 without playing a game, then signed by the Ravens last week, was flagged for holding Boldin in the first quarter to set up Dawson's second field goal. Torrey Smith burned the cornerback on his career-long TD, capping a 49-second, two-play drive that made it 13-3.
Wright yielded a 26-yard gain to Boldin on another drive that ended with a field goal by Dawson, and then fell down on Patton's TD catch.
"It was a quick week, but I've got to be ready," Wright said.
Early in the third with no intended receiver in sight, Flacco threw right to 49ers cornerback Kenneth Acker, who returned the interception 45 yards.
Baltimore, making its second Bay Area trip in less than a month after a loss at Oakland on Sept. 20, had won four straight against San Francisco, including that 34-31 Super Bowl victory at the Superdome.
49ers left tackle Joe Staley acknowledged during the week the offense prematurely spoke in the huddle late of having a victory parade.
Kamar Aiken added a 2-yard touchdown catch for the Ravens, who had won six in a row against NFC teams and dropped to 19-10 vs. the NFC under Harbaugh.
Copyright 2015 by The Associated Press