SANTA CLARA, Calif. -- Colin Kaepernick completed a 76-yard touchdown pass to ex-Ravens star Torrey Smith, Joe Flacco threw two interceptions and the San Francisco 49ers beat Baltimore 25-20 on Sunday to snap a four-game losing streak.

Phil Dawson kicked four field goals in the first win since Week 1 for San Francisco (2-4), while Anquan Boldin -- a Super Bowl star for the Ravens against the Niners -- made a 51-yard reception late that set up Quinton Patton's 21-yard TD catch.

advertisement | advertise on newsday

Flacco's desperation pass to the end zone on the final play went incomplete.

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 from Flacco 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 brother Jim's Michigan team lost Saturday to Michigan State on a botched punt.