MIAMI — This trip to the Eastern Conference finals did not come easily for Miami.

MIAMI — This trip to the Eastern Conference finals did not come easily for Miami.

Down by eight with less than five minutes left, after trailing for virtually the entire game, the Heat found a way nonetheless to finish off the Brooklyn Nets and move into the NBA's final four for the fourth straight season.

Ray Allen's 3-pointer with 32 seconds left highlighted a huge Miami rally, and the Heat beat the Nets 96-94 in Game 5 of the Eastern Conference semifinals on Wednesday night. The Heat won the series 4-1, improving to 9-0 at home in chances to close out series over the last four seasons.

LeBron James scored 29 points and Dwyane Wade added 28 for the Heat, with Chris Bosh scoring 16 and Allen finishing with 13. James made one of two free throws with 9.5 seconds left to put the Heat up by two, and the Nets almost failed to get a potentially game-tying shot off after Paul Pierce lost it out of bounds, but it stayed with Brooklyn after replay.

And the Nets still couldn't get a shot away: Allen knocked it away from Joe Johnson as he made his move, and time expired.

Johnson had 34 points, Pierce scored 19 and Deron Williams had 17 for the Nets.

It's the sixth trip to the East title series in the last 10 seasons for Miami, which is bidding for a fourth straight trip to the NBA Finals — something only the Lakers and Celtics franchises have accomplished.

James is heading there for the sixth time in eight seasons, the first two of those trips coming with Cleveland in 2007 and 2009.

The Heat will next face either fifth-seeded Washington or top-seeded Indiana. The Pacers lead that series 3-2, one win away from setting up a rematch with Miami that seemed like an absolute certainty for much of the season.

The tone for this one was set early, Brooklyn running out to an 11-4 lead before the game was three minutes old, clearly and predictably the more desperate team from the outset. The Heat weathered the early storm and when James Jones connected on a 3-pointer with 3:02 left in the half, Miami held a 42-41 lead.

Miami scored the first seven points of the second half, tying the game, before Brooklyn immediately answered with seven straight points of its own. The Nets extended the lead to 61-51 midway through the third on a 3-pointer by Williams, and whenever Miami tried to put together a run Brooklyn found a way to keep things together.