"It was difficult for me to close out those sets," Halep told reporters, praising Kozlova.
"When I was leading the match, she played without fear."
The victory advanced the French Open champion, who won Indian Wells in 2015, to the fourth round for the fifth time in six years.
The meeting was the first between the pair and featured big momentum swings.
After Kozlova claimed a 3-2 advantage in the first set, Halep won three consecutive games to go to set point at 5-3 on Kozlova's serve.
With the former world number one's groundstrokes failing her, Kozlova reeled off 11 of the next 12 points, breaking back for 5-5 with a forehand winner.
Halep finally won the set on her third opportunity with another trademark backhand down the line.
The Romanian took four successive games for a 5-2 lead in the second set, but Kozlova again rallied to even the match at 5-5 before Halep reeled off the eight straight points to seal the win.