Yet thanks to in large part to a defense led by J.J. Watt, the Texans are still in playoff contention with one week left in the regular season.
With three quarterbacks hurt, the Texans started Case Keenum, who got his first win in nine NFL starts.
"It's pretty special," Watt said. "I think it's a testament to our team. It's a testament to the coaching staff, to guys we have. It was fun. Days like this are a blast."
The Ravens (9-6) now need some help next week to get into the postseason after Joe Flacco threw a season-high three interceptions and the offense struggled all day.
Houston (8-7) needs several teams to lose next week to reach the postseason for the third time in franchise history.
"That's why we play, is to get in to the dance," Foster said. "We didn't put ourselves in position to control our own destiny, but we gave ourselves a chance and as long as we have that chance we're going to keep fighting."
Keenum lost each of his eight starts last season before being released by the Texans in training camp. They signed the former record-setting University of Houston star off the St. Louis practice squad Monday after both Ryan Fitzpatrick and Tom Savage were injured last Sunday with Ryan Mallett already out for the season.
"I'm not the best with words, and I couldn't put it into words," Keenum said. "Arian said he was going to punch me if I cried. When you don't win, it makes winning very, very sweet."
Keenum threw for 185 yards with an interception.
Five things to know about Houston's win over the Ravens.
FOSTER'S ARM: Foster ran for 96 yards. But his highlight came when he took a pitch from Keenum and, with a defender in his face, threw a 5-yard touchdown pass to C.J. Fiedorowicz to make it 16-0 in the second quarter.
He's been waiting forever for a chance like this.
"My whole life, actually," Foster said. "Everybody wants to be a quarterback. I feel like I have a good arm. So I've been lobbying since I've been in the NFL. They finally called it."
NOWHERE TO RUN: The Ravens finished with a season-low 33 yards rushing, the fewest Houston has allowed all season. Flacco took the blame for some of the struggles in the running game.
"Part of it was getting me off the spot and then part of it was them stopping the run," Flacco said. "That just shows that they were playing well up front. If we are not getting our running game going, it is going to affect us. Our running game wasn't working though for a reason. They were playing physical and they were playing well up there."
WATT'S NOSE: Houston defensive end J.J. Watt, who had a gash on the bridge of his nose that would open up and bleed in almost every game last season, got another injury to it on Sunday. He was hit in the nose midway through the fourth quarter and had blood running down his face into his mouth for a few plays before trainers tended to the injury.
He said after the game that it felt as though he got hit in the face with a sledgehammer.
But he found the best medicine to ease the pain.
"Everything feels better after a win," Watt said. "So I don't feel it too much."
The injury didn't slow him down any and he finished with a season-high eight tackles and had a sack, four quarterback hits and three tackles for losses. He has 17 1/2 sacks this season and a franchise-record 54 in his career.
UNHAPPY HOMECOMING: Sunday was a homecoming for former Texans coach Gary Kubiak, who is now Baltimore's offensive coordinator. Kubiak, who grew up in Houston, was fired last year in his eighth season with the Texans. Ravens running back Justin Forsett, receiver Jacoby Jones and tight end Owen Daniels also previously played for the Texans.
"It wasn't ideal," Daniels said of his return to Houston. "It was an experience to be back here. I thought it was going to be pretty weird and it was."
THIEVES: The Texans had three takeaways on Sunday to give them a franchise-record 34 this season, which tops the NFL. They've scored 123 points off those turnovers, which is also a team-record.