ORCHARD PARK, N.Y. — The Bills finally built a lead they couldn't squander, and upstaged Willis McGahee in his first game back to Buffalo.

Making good on an opportunity to secure the starting job, rookie quarterback Trent Edwards went 11-of-21 for 153 yards and engineered five scoring drives in helping Buffalo to a 19-14 win over the Baltimore Ravens on Sunday.

The Bills' defense did its part, limiting the Ravens to two scores despite six drives into Buffalo territory. That included Baltimore's final drive when Kyle Boller couldn't convert a fourth-and-1 from the Buffalo 49, his pass falling just out of the reach of Musa Smith with 1:49 remaining.

The Bills improved to 2-4 and eased memories of their last outing, a 25-24 loss to Dallas in which Buffalo squandered an eight-point lead in the final 20 seconds. It was the second game Buffalo lost in the final seconds after a 15-14 loss to Denver in the season opener.

Rian Lindell hit four field goals, including a 41-yarder, and Marshawn Lynch scored on a 1-yard plunge, giving the Bills a 19-7 lead late in the third quarter.

McGahee made his mark, overcoming a slow start and a booing crowd, by scoring on a 46-yard run in his first game back since the Bills traded him to Baltimore in March. But it wasn't enough for a popgun Ravens attack that featured three rookie offensive linemen and was minus starting QB Steve McNair and tight end Todd Heap.

Boller went 21-of-36 for 191 yards in making his second straight start in place of McNair, who's nursing a sore back and groin injury.

The banged-up Ravens enter their bye with an opportunity to get healthy. For the second straight game they started three rookie offensive linemen. And they were also down starting cornerback Chris McAlister (knee) and tight end Todd Heap (thigh).

The Ravens' offense sputtered in the first half, managing one first down and 29 yards on its first three possessions. Baltimore lacked discipline, penalized 11 times for 91 yards.

Edwards played an efficient game, his outing nearly ruined when he made a bad pass intended for Lee Evans that was intercepted by Samari Rolle at the Bills 14 midway through the fourth quarter. The turnover set up Derrick Mason's 15-yard scoring catch on fourth-and-11.

Edwards, a rookie third-round draft pick, was making his third straight start in place of J.P. Losman — and first since Losman recovered from a sprained left knee. Edwards has now produced both Bills victories, showing signs he deserves to remain the starter.

The one knock against Edwards is he and the offense lack finishing power.

The Bills led 9-0 at the half, settling for three field goals despite three drives inside the Ravens 20. That included Buffalo managing minus-1 yard after a pass interference penalty on Rolle gave the Bills a first-and-goal from the 7.

Edwards did hit Evans for a 54-yard gain in engineering a five-play, 71-yard drive capped by Lynch's score late in the third quarter.

Lynch has now accounted for four of five touchdowns scored by the Bills' offense, and he finished with 84 yards rushing.