Masterson (2-0) went 5 1/3 innings, allowing just the one run on six hits with four strikeouts and one walk for the Red Sox, who swept the Yankees in three games for the first time since April 2007.
Hunter Jones and Michael Bowden shut out the Yankees in relief and Takashi Saito pitched a scoreless ninth to get his second save.
Andy Pettitte (2-1) took the loss after going six innings, allowing four runs in six hits with four walks and six strikeouts.
The Yankees scored first when Hideki Matsui singled and then scored on a one-out sacrifice fly by Brett Gardner in the third.
Ortiz drove in the tying run in the bottom of the third with a sacrifice fly that scored Jacoby Ellsbury. After Ortiz doubled to drive in Jason Varitek in the fifth, Ellsbury stole home to make it 3-1 and Ortiz scored on a ground-rule double by J.D. Drew to cap the scoring.