MADRID, Spain (AP) _ David Beckham was minutes away from a perfect Hollywood ending.
The 32-year-old soccer star-pop icon, who likely played his last professional game in Europe, was taken off the field moments before Real Madrid rallied to win the Spanish league title for the first time in Beckham's four years with the team.
The England midfielder was replaced in the 66th minute with what appeared to be a recurrence of an ankle injury. But he still managed to limp around the field in celebration _ in front of a huge crowd that included wife Victoria and friends Tom Cruise and Katie Holmes _ after his team beat Mallorca 3-1 to win its 30th league title.
It was the culmination of a season that can easily be called the most difficult of his life. But even being shunned by both Madrid coach Fabio Capello and England coach Steve McClaren over the last year didn't keep Beckham from proving he still has the skills to compete at the highest level.
``It has been possibly the toughest season of my career on and off the field. I've gone through things that I never thought were possible,'' said Beckham, who was dropped from the Madrid lineup in January after signing a five-year, $27.5 million contract to play for the Los Angeles Galaxy of MLS.
But with Madrid again eliminated early from the Champions League and the team in fourth place in the league _ six points behind leader FC Barcelona _ Capello begrudgingly recalled the former England captain.
``A major fault of mine this season was not recognizing Beckham's potential,'' Capello said Sunday.
Beckham, whose good looks and pop star wife have made him an international marketing magnet, marked his return to the team by scoring with a bending free kick in Madrid's 2-1 win at Real Sociedad.
After missing six weeks with a knee injury, Beckham returned to set up the winning goal in a 2-1 win over Valencia.
Madrid rode an eight-game unbeaten run by scoring 24 goals _ more than a third of the total it had scored in the first 30 games of the season.
On Sunday, Beckham nearly scored with a free kick in the 18th minute, and then watched as another one went over the crossbar in the 52nd. Six minutes later, Beckham hit the bar with another.
But Beckham appeared to re-aggravate his left ankle sprain and he was replaced by Jose Antonio Reyes, who scored two of Madrid's three goals.
After the game, Beckham did a lap of honor with an England flag draped across his back, soaking in the atmosphere at the famous Santiago Bernabeu stadium for one last time.
Beckham arrived at Madrid in 2003 with nine major trophies from his days at Manchester United. Lining up alongside Zinedine Zidane, Ronaldo and Luis Figo, Beckham was the last ``galactico'' _ sure to fill the club's pockets with marketing money while the nine-time European champions continued to collect trophies.
But life in Madrid was tough for Beckham. The club went four years without winning a trophy _ its longest drought in 53 years.
A new language, six different coaches and three club presidents during his spell led to incessant criticism that Madrid was not a team, but a collection of players.
``I've gone through things that I never thought were possible,'' Beckham said. ``Things have happened here that never happened at Manchester United. Not being involved in matches or in training and having things said about me that were not true was hard.''
Beckham's first season began in promising style, with the Englishman scoring in his first game at the Bernabeu as Madrid won the Spanish Supercup by beating Mallorca.
It turned out to be his only chance before Sunday to take a victory lap at the Bernabeu, despite the club winning three of the previous six Champions League titles and two Spanish league titles before his arrival.
Despite the lack of trophies, the midfielder's determination and fiery temper _ he has picked up 14 cards in 22 games this season, including one red _ saw his standing with the home fans remain steady.
The same can be said of his supporters in England, who enthusiastically welcomed Beckham back to the national team for the European Championship qualifying competition. The former captain responded by setting up two of England's goals in its 3-0 win over Estonia.
``There's no doubt I could have stayed with Real Madrid for two or three more years, or for the rest of my career,'' Beckham said. ``I had to make a decision when I was told I was leaving the club at the end of the season. I've had 15 years playing top flight football for Real Madrid and Manchester United, but I'm moving on to a new challenge.''
Instead of playing in front of 90,000 fans at Madrid and Barcelona, Beckham will turn out in front of about 8,000 at some Major League Soccer games, even though his presence will inevitably boost attendance.
``David Beckham will have a greater impact on soccer in America than any athlete has ever had on a sport globally,'' Timothy J. Leiweke, president and CEO of AEG and owner of the Galaxy, said after the signing.
With that in mind, Beckham can depart for America with one challenge accomplished, and ready for the next.