Philippe Coutinho took only 92 seconds to give Barca the lead at Wembley on Wednesday, with Rakitic's unstoppable 25-yarder doubling the Catalan side's first-half advantage.
Harry Kane's 10th Champions League goal gave Spurs hope and, although Messi soon put Barca 3-1 up, Erik Lamela struck to set up a grandstand finish.
Ernesto Valverde's men had failed to win their last three games and looked nervy in the closing stages, but Messi capitalised on poor defending in the last minute to ensure his team join Inter on maximum points after two games in Group B.
Hugo Lloris was playing for the first time since August after recovering from a thigh injury but the Tottenham captain's mistake contributed to Barca's second-minute opener.
Messi produced a gorgeous ball to send Jordi Alba scampering clear down the left channel and, with Lloris having raced out and left his goal unmarked, the left-back squared for Coutinho to tuck away his first Barca goal in the Champions League.
The visitors, returning to Wembley for the first time since lifting the Champions League there in 2011, extended their lead in stunning fashion soon after Kane had Spurs' first shot.
Coutinho performed a minor miracle to keep the ball in play on the byline with Rakitic launching himself into a sensational 20-yard volley that clipped the post on its way into Lloris' net.
Marc-Andre ter Stegen made a great save to keep out a Son Heung-min cross that sharply deflected off Gerard Pique, who was making his 100th Champions League appearance, and Messi hit the post twice in five minutes after the restart before Kane gave Spurs a lifeline.
A long throw from Lloris set up a counter, with Lamela feeding Kane to turn Nelson Semedo and bend a fine finish into Ter Stegen's bottom-left corner.
Messi would not miss again, though, sending Alba clear down the left with a trademark curling pass and timing his run into the box perfectly to slot a first-time finish past Lloris to restore Barca's two-goal lead four minutes later.
Lamela's deflected strike wrongfooted Ter Stegen and ensured a fantastic finale but, with Spurs committing men forward, Alba seized on a loose pass to set up Messi to sweep home his second.
What does it mean: Crisis over for Valverde
Valverde said after Barca lost at Leganes last month that every defeat is an "earthquake" for the club, with talk of crisis intensifying after he rested Messi and saw his side held by Athletic Bilbao at the weekend. Spurs put up a better fight after the interval, but Barcelona's second win in eight away Champions League games is a positive sign the LaLiga giants are getting back on track.