"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."
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.
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.
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.
"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.
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.
Copyright 2015 by The Associated Press