SAN FRANCISCO -- Mario Manningham decided to sign with the San Francisco 49ers before he even knew if Peyton Manning or Alex Smith would be throwing him passes.

He was attracted by the punishing defense, the strong running game and a coaching staff he trusted.

The 49ers announced Thursday that Manningham had signed a two-year deal to join the team he helped knock out in the NFC championship game two months ago in their latest offensive upgrade at wide receiver. The team also announced Thursday it re-signed Ted Ginn Jr. to a one-year deal.

San Francisco also agreed to a two-year deal with quarterback Josh Johnson, a league source told ESPN's Josina Anderson. Johnson, a fifth-round pick in 2008, spent his first four seasons as a reserve with Tampa Bay. Johnson played for 49ers coach Jim Harbaugh in college at San Diego.

Manningham agreed to the deal last Saturday when the 49ers were in the thick of the race to sign Manning, the four-time NFL MVP and brother of his old quarterback with the New York Giants, two-time Super Bowl winner Eli Manning.

Peyton Manning ended up choosing to sign with Denver and the Niners brought back Smith.

"I wanted to go there and I knew that Peyton Manning was going to go somewhere. I thought he was coming to the 49ers but he didn't," Manningham said. "He went to Denver. Good luck to him with that. I wish the best for him. We got Alex Smith and I know he's a great player.

"I knew (playing with Manning) was a possibility but I wasn't picking them because of that. I know Peyton Manning is a great quarterback and everything but if you don't have a good defense ... offense can be potent but there's really no point."

The 49ers defense was one of the best last season and played a big part in the team's 13-3 record and trip to the NFC title game that ended with a 20-17 overtime loss to Manningham and the Giants.