SAN FRANCISCO -- The Giants retained their left-handed bullpen complement and thus addressed one of the biggest issues facing them this offseason Sunday by signing Javier Lopez to a two-year, $8.5 million contract and picking up Jeremy Affeldt's $5 million contract option for 2012.

Lopez, 34, would have become a free agent after midnight Sunday. His effectiveness overall and as a left-handed specialist in particular made him among the most highly ranked performers eligible to go on the open market.

"I wrestled with wanting to test the waters, but ultimately trying to get back to the playoffs with these guys really made the decision easy," Lopez said in an e-mail response. "The pitching staff from top to bottom is special and being able to be a part of that excited me, too. Knowing the coaching staff and how [manager Bruce] Bochy and Rags [pitching coach Dave Righetti] use us helped as well. Getting Buster [Posey] and Freddy [Sanchez] back will really be nice. Both guys can only add to our offense and they were really missed."

Lopez's possible free agency apparently wasn't the only factor influencing the timing of the agreements. Affeldt said that his agent, Michael Moye, was attempting to negotiate a multiyear deal with the Giants. But, Affeldt said, "There were some logistical things to work out that didn't make sense for both sides."

Affeldt shared the widespread assumption that the Giants would retain either him or Lopez but not both. The Giants still must ponder decisions regarding six free agents and 13 salary arbitration-eligible players, which will strain their payroll. So when he learned of Lopez's deal, he figured that his three-year tenure as a Giant had ended. He then would have received a $500,000 buyout and entered free agency.

"So when they told me they were going to pick up my option, I was like, 'That's awesome,'" Affeldt said. "I enjoy being a Giant."

Aside from Affeldt and Lopez, the Giants' most experienced left-handed reliever is 26-year-old Dan Runzler, who was 1-2 with a 6.26 ERA in 31 appearances (one start) in 2011. Moreover, none of the potential replacements likely to test free agency (Mike Gonzalez, John Grabow, Damaso Marte, Trever Miller, Darren Oliver, Arthur Rhodes, J.C. Romero, George Sherrill, Brian Tallet) represents a significant upgrade over Lopez or Affeldt.

"As of last year, I think we did a pretty good job of making ourselves known as some of the better left-handers in the game," Affeldt said. "For them to bring us both back instead of one, it shows how much respect they have for me and Javy."

Lopez, who earned $2.375 milllion this year, enjoyed one of his best seasons in 2011, finishing 5-2 with a 2.72 ERA in 70 games. Opponents hit .221 off him, while left-handed batters mustered a mere .163 batting average.

Since joining the Giants from Pittsburgh in a 2010 Trade Deadline deal, Lopez has made 97 appearances without allowing a home run. This year, he and Brad Ziegler were the only Major League relievers who pitched at least 50 innings not to yield a long ball. He also permitted six of 43 inherited runners to score -- a 14 percent rate that was tied for third lowest in the National League.

"Anytime you win a World Series with a club, that automatically puts them at the top of the list," Lopez said in his e-mail, referring to the Giants' 2010 title. "SF is a great city and a great place to play. The fan support is amazing and it's a place where I feel comfortable playing."

Affledt, 32, finished 3-2 with a 2.63 ERA in 67 games before Sept. 8, when he accidentally cut his right hand while trying to separate frozen hamburger patties and was sidelined for the rest of the season. He limited left-handed batters to a .144 average, third best in the Majors behind Jonny Venters (.127) of the Braves and Koji Uehara (.130) of the Orioles and Rangers.

A Giants spokesman announced the deals' completion, which club management is expected to address officially Monday.