Two-time champion Fernando Alonso will leave Formula One at the end of the season and potentially move to IndyCar in the United States.

McLaren Racing confirmed Tuesday the Spaniard will not return to F1 next year for an 18th season, and Alonso said F1's leadership group tried to persuade him to stay with the series.

"I made this decision some months ago and it was a firm one," Alonso said in a statement. "Nevertheless, I would like to sincerely thank Chase Carey and Liberty Media for the efforts made to change my mind and everyone who has contacted me during this time."

There is speculation that McLaren will enter IndyCar with Alonso as one of its drivers. Alonso ran the Indianapolis 500 last year and was in position to win the showcase race until his engine failed.

He also ran the Rolex 24 at Daytona as a warm-up for the 24 Hours of Le Mans, in which Alonso was part of the winning team. Alonso has been pursuing the top motorsports events and has said he would like to return to Indianapolis and add a win in "The Greatest Spectacle in Racing" to his resume.

"Let's see what the future brings," Alonso said in a statement, "new exciting challenges are around the corner. I'm having one of the happiest times ever in my life but I need to go on exploring new adventures."

Alonso has 32 career F1 wins, 22 poles and 97 podiums. He won two world titles and was runner-up three times.

IndyCar, Indianapolis Motor Speedway and NASCAR used social media accounts to urge Alonso to race next year in the U.S. following his announcement. NASCAR mocked up a formal invitation to the Daytona 500 that "requests the honour of your presence."

Alonso is in his fifth season driving for McLaren and had hinted on social media he had an announcement coming. He delivered with a farewell video to F1 and in it noted "today I have some other bigger challenges than you can offer me" as the camera showed Alonso standing in front of his Indy 500 helmet.

Alonso enjoyed his one IndyCar race, which was a partnership between Andretti Autosport and McLaren. He led 27 laps and had one of the strongest cars on the track until the engine failure ended his race. IndyCar drivers have openly called for him to return to the series.

"It would be appealing to me, if I were him," said Ryan Hunter-Reay, winner of the 2014 Indianapolis 500. "He's as hungry as ever to win. I think IndyCar is a great spot. This series is the most competitive series in the world. You cannot name who is going to win each race. There are no favourites."

That's not the case in F1, where only a handful of drivers are in contention each round. The top teams are evident at the start of each season and catching the leaders is a virtually impossible task. At 37, Alonso is behind only Kimi Raikkonen as the oldest driver on the F1 grid. His last championship was in 2006 and his last F1 victory was in 2013.

He made a second return to McLaren in 2015 with the belief he could help turn around the team as it paired with manufacturer Honda. It led to three frustrating seasons as McLaren-Honda was unreliable and unable to compete. Alonso didn't hide his unhappiness and McLaren split with Honda at the end of last season.

Now with Renault, McLaren is still struggling and Alonso, who is currently ninth in the standings, had been debating his future.

He was not permitted to skip the Monaco Grand Prix to return to Indianapolis in May, but he was allowed to compete in the World Endurance Championship superseason and enter Le Mans. A two-time winner at Monaco and now a Le Mans winner, Alonso only needs to win the Indy 500 to complete motorsports' unofficial "Triple Crown."

Zak Brown, CEO of McLaren, called Alonso "the pre-eminent driver of his generation."

"There is a time for everyone to make a change and Fernando has decided the end of this season to be his," Brown said. "We respect his decision, even if we believe he is in the finest form of his career. Our open dialogue with Fernando has meant we could plan for this eventuality. While evaluating his future during the past months, Fernando's competitiveness has been undimmed. He has continued to perform at the highest level throughout, as we know he will do in the remaining nine races of this year's championship."

Brown was a key player in Alonso's entry at Indianapolis, Daytona and Le Mans. He supported Alonso's quest to enter other series and signed off on the driver skipping the Monaco Grand Prix in 2017 to race at Indianapolis.

Brown is also behind McLaren's potential entry into IndyCar and the team is believed to have courted four-time IndyCar Series champion Scott Dixon to be Alonso's teammate. Dixon on Monday announced a contract extension to remain with Chip Ganassi Racing, but acknowledged the presence of McLaren in his free agency talks made it a "noisy" process.