SAN FRANCISCO — After addressing their holes in the pitching rotation early in free agency, the San Francisco Giants filled their biggest remaining need Thursday.

The Giants agreed on a $31 million, three-year deal with free-agent Denard Span, giving them the outfielder and leadoff hitter they had sought.

Span passed a physical and he will be officially introduced at a news conference on Friday.

“I’m very pleased to strengthen our ballclub with an excellent fielder and solid top-of-the-order hitter who has a great track record,” general manager Bobby Evans said. “When you invest in pitching like we did this winter, it’s important to invest in the defense behind them. We hope this makes us stronger and deeper and better prepared to enter 2016 with the strongest lineup and strongest defense possible.”

It has been a pricey offseason for the Giants, who missed the playoffs last year after winning their third World Series title in five seasons in 2014. San Francisco signed right-handers Johnny Cueto to a $130 million, six-year contract and Jeff Samardzija to a $90 million, five-year contract to bolster the pitching staff behind ace Madison Bumgarner.

The team also signed shortstop Brandon Crawford to a $75 million, six-year contract extension, raising the offseason tab to $326 million for the four players who will solidify the team up the middle.

Span, who will turn 32 next month, batted .301 with five homers, 22 RBIs and a .365 on-base percentage in 61 games last season with Washington. He missed time with injuries to his back, left hip and right core but is expected to be completely healthy close to the start of spring training.

advertisement | advertise on newsday

In an eight-year career with Washington and Minnesota, has a .287 career average, with a .352 on-base percentage and .395 slugging percentage. He also has 152 career stolen bases and is a contact hitter who fits the Giants’ style of play. Span has averaged 9.34 plate appearances per strikeout the last five seasons, which ranks as the fourth-best figure among big league outfielders.

Span has experience playing all three outfield positions. Span and Angel Pagan will handle left and center field duties with specific spots determined in spring training. Span is an elite fielder, ranking third among all outfielders since 2008 in putouts per nine innings (2.67).

Nori Aoki and Pagan split time in the leadoff spot last year for the Giants. San Francisco declined a $5.5 million option to keep Aoki and was looking to upgrade from Pagan, who had a .310 on-base percentage last season and has been limited by injuries the past three years.

Span can earn up to $5 million in additional money over the length of the contract in performance bonuses based on plate appearances and games played. There is also a $12 million mutual option for a fourth season with a $4 million buyout.