Derek Fisher added 14 points and seven assists for the Lakers, who gave up a season-high 44 points in the first quarter, but had enough defense at the end to win for the fourth time in the last five games.
Dwight Howard led the Magic with 19 points and 11 rebounds, but played only 29 minutes because of foul trouble. Jameer Nelson added 17 points and nine assists for the Magic, who had seven players score in double figures, but couldn't contain Bryant and Gasol.
Bryant hit two free throws with a minute to play to give the Lakers a 113-112 lead. Howard was called for goaltending on a shot by Lamar Odom with 30.5 seconds to make it 115-112.
Rashard Lewis missed a three-pointer with 15 seconds to play that could have tied the game and Bryant settled the issue with two more free throws to make it 117-112.
The Lakers trailed 64-63 at halftime, but started the second half with a 15-4 run to go ahead for the first time. Howard got his fourth and fifth on consecutive possessions and was back on the bench with 5:22 left in the third period.
Bryant drew the fifth foul on a drive to the basket and converted the layup for the first of three straight three-point plays for the Lakers. Gasol had the last of those and two more jumpers in the 11-2 run that pushed Los Angeles' lead to 89-75. The Lakers settled for a 98-87 lead going in the fourth quarter.