Danish driver Kevin Magnussen said he had given up hope of a Formula One comeback until Haas team boss Guenther Steiner offered him the seat of sacked Russian Nikita Mazepin.

The 29-year-old told reporters he accepted immediately.

"I wasn't really thinking about Formula One a lot," said Magnussen, who competed in sportscars in the United States last year and was set to race for Peugeot in the world endurance championship as well as entering Le Mans with his father Jan.

READ | F1 Pre-Season Testing: 'Extreme' Mercedes makes waves in Bahrain on day one

"I'd kind of really, truly accepted that Formula One was a closed chapter."

Magnussen said he saw Haas had terminated Mazepin's contract but did not think he had a chance of returning to the team he last raced for in 2020.

Mazepin's billionaire father, now on the EU sanctions list after Russia's invasion of Ukraine, had provided the team's title sponsorship and Magnussen assumed Haas would want a replacement with funding.

Their other driver is Ferrari-backed Mick Schumacher, son of seven times champion Michael.

"I don't bring a lot other than just my driving skills to a team so I thought that was still not going to be a possibility and then Guenther called me and that was a big surprise," said Magnussen at testing in Bahrain ahead of the March 20 season-opener.

"I felt really excited when he called me and asked if I wanted to come back.

"I said yes immediately. Then afterwards I kind of thought about it."

Magnussen said a rules revolution for 2022 opened the possibility of better opportunities.

The comeback will be his second in a career that started with McLaren in 2014 before stalling after a year on the sidelines in 2015.

Informed by email on his birthday that McLaren were casting him aside, he joined Renault at short notice before the start of the 2016 season when Venezuelan Pastor Maldonado lost his funding.

Magnussen then moved to U.S.-owned Haas for 2017.

READ | Vettel sports helmet in support of Ukraine during Bahrain pre-season test

He spoke last year of lost motivation as a backmarker in 2020 and not wanting to return unless he had a chance of winning, but those comments were easily shrugged off on Thursday.

"It's one thing saying all that stuff when you don't have an opportunity to go to Formula One," he said. "When you actually have an opportunity to go back, it's different.

"It's also a way of coping. There's no reason to look back. I got asked quite a lot 'would you like to go back' and I got tired of all those questions. It's easier to deal with if you say "No, I'm looking forward, I've moved on'.

"But when you get that opportunity, you take it."