By Steve Keating

RIO DE JANEIRO (Reuters) - Spain beat Australia 89-88 in a thrilling clash to take bronze in the Olympic men's basketball tournament on Sunday and bring home a medal from a third straight Games.

For Australia, who had set an ambitious gold medal target, it was another bitterly disappointing end to what looked a promising Olympics.

Once again the Boomers let an elusive medal slip through their fingers, losing in the bronze medal match for the fourth time and in the cruelest of fashion.

With five seconds left in regulation time, Sergio Rodriguez drew a controversial foul and made two free throws to give Spain a one point lead and Australia one last possession.

But Australia could not get a shot off as the Boomers were once again denied an elusive medal having now lost in the bronze medal match at four Games.

"It's unbelievable," said Australian center Andrew Bogut. "You just dive into guys recklessly and get calls like that.

"It's tough to play like that. We're disappointed. We had a horrible semi-final, we battled tonight and times we were outnumbered on the court.

"You touch one of these guys and they go flying and the refs buy it. The last two fouls were tough on us."

Spain had looked poised to run away with the bronze, opening up a 10-point lead in the final minutes of the opening half, when Australia hit back-to-back threes from Patty Mills and David Andersen, who followed with a pair of made free throws, to chop the deficit to 40-38 entering the break.

With a medal on the line, the final quarter was tense and tight with no more than three points separating the two sides over the final nine minutes, the lead changing hands more than a dozen times.

When Aron Baynes muscled in a basket for an 88-87 lead with 9.7 seconds remaining, it looked as if Australia's medal drought was over.

But it was not to be, Spain extending its podium run to three Games, adding bronze to silver medal efforts at the 2008 Beijing and 2012 London Olympics.

"It was a great result for our team, the way everything played out, the slow start, the two tough losses that we started with (in group play)," said Spain's Pau Gasol, who poured in a game high 31 points and added 11 rebounds. "This game was just an incredible battle between two teams that really wanted to get an Olympic medal."

The United States take on Serbia in the gold medal game later on Sunday.

(Additional reporting by Chris Gallagher. Editing by Ken Ferris and Bill Rigby)