OL said in a statement they had agreed to pay Sampdoria an initial 24 million euros for the 23-year-old, with a further six million euros in potential bonuses.
That means the 1.90m tall centre-back becomes the club's most expensive player ahead of Brazilian midfielder Thiago Mendes, who signed from Lille for 26.5 million euros earlier this month.
Formerly with Twente Enschede in the Netherlands, Andersen moved to Italy in 2017. He has yet to be capped by Denmark at full international level.
"Signing him was one of our priorities. We had watched him very closely. We are delighted to have him," said Lyon president Jean-Michel Aulas.
He is Lyon's fifth major signing of the summer following the arrival of a new Brazilian management team, with club legend Juninho Pernambucano returning as sporting director and Sylvinho appointed coach.
As well as Andersen and Mendes, Lyon have signed Malian left-back Youssouf Kone from Lille for nine million euros, young Brazilian midfielder Jean Lucas from Flamengo, and giant Romanian goalkeeper Ciprian Tatarusanu from Nantes.
The spending spree has been funded by the big-money sales of French international duo Ferland Mendy and Tanguy Ndombele.
Left-back Mendy moved to Real Madrid for a fee reportedly reaching 53 million euros, while powerful midfielder Ndombele has signed for Tottenham Hotspur for up to 70 million euros.
Lyon will be in the Champions League again next season after finishing third in Ligue 1.