McLaren has announced Fernando Alonso will retire from Formula One at the end of the 2018 season.

The Spaniard's future in the sport has remained uncertain due to McLaren's inability to give him a race-winning car. Alonso has been racing in the World Endurance Championship alongside his F1 commitments -- winning the Le Mans 24 Hours in June -- and he has openly admitted he would be keen to race at the Indianapolis 500 again.

Alonso has two F1 titles to his name and has finished runner-up on three occasions. He leaves F1 with 32 grand prix victories as well as 97 podium finishes.

In a statement released by McLaren, Alonso said: "After 17 wonderful years in this amazing sport, it's time for me to make a change and move on. I have enjoyed every single minute of those incredible seasons and I cannot thank enough the people who have contributed to make them all so special.

"There are still several grands prix to go this season, and I will take part in them with more commitment and passion than ever. Let's see what the future brings; 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 hasn't stood on the top step of the podium in F1 since 2013, while driving for Ferrari. Marco Canoniero/LightRocket via Getty Images)

"I want to thank everyone at McLaren. My heart is with the team forever. I know they will come back stronger and better in the future and it could be the right moment for me to be back in the series; that would make me really happy. I have built so many great relationships with many fantastic people at McLaren, and they have given me the opportunity to broaden my horizons and race in other categories. I feel I am a more complete driver now than ever.

"I made this decision some months ago and it was a firm one. 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.

"Finally, I would also like to thank my former teams, team-mates, competitors, colleagues, partners, journalists and everyone I have worked with in my F1 career. And, especially, my fans all over the world. I am quite sure our paths will cross again in the future."