BALTIMORE -- Kyle Shanahan had two goals Sunday when the 49ers took over at their own 23-yard line with 1:58 remaining in the first half.

“When we get that ball at the end of the second quarter, our No. 1 goal is to finish with the ball in our hands,” the coach said after his 49ers' 20-17 loss to the Baltimore Ravens. “We’d love to score, and we also want to work that clock.”

Actually, the 49ers failed twice. They did not score, and a Ravens player touched the ball last when Marlon Humphrey, a starting cornerback, got his hand on Robbie Gould’s 51-yard field-goal attempt as time expired at the end of the first half.

"I think it got a little tipped from what I saw," Shanahan said. "We were short on the field goal. I wish we had gotten closer so we're not short on the field goal."

Trailing 17-14 late in the first half, the 49ers moved the ball 42 yards on seven plays with five pass plays and two called runs. Raheem Mostert had a 19-yard run on the first play after the 49ers took possession. The 49ers huddled up and did not snap the ball again until there was 1:20 left in the half.

Then, the 49ers had a first-and-20 from their own 34 after receiver Emmanuel Sanders was called for an illegal block above the waist. After a short gain on a pass play with 1:13 left in the half, the 49ers did not run another play until there were 32 seconds remaining.

“We were pretty far back there,” Shanahan said. “We wanted to eat up the clock, and once we got to a minute, push it a little bit. And that’s what we did.

"We didn't get enough chunk plays at the end. I wish we had made it [the field goal]."

Mostert ran the ball on a second-and-12 play and picked up 16 yards. In the final 26 seconds, the 49ers picked up 5 yards on a penalty, then attempted three passes before settling for Gould’s field-goal attempt.

[RELATED: Where 49ers stand in NFC playoff race after loss vs. Ravens]

With 10 seconds left in the half, quarterback Jimmy Garoppolo hit Mostert on a 3-yard pass on third-and-4 to leave Gould with the long kick. Gould was in his first game back after missing three games because of a right quadriceps injury.

“It’s difficult,” Garoppolo said. “It’s very difficult just dealing with the timeouts and how much time is left. You obviously don’t want to give them another opportunity, so I thought we did a good job with that. We could’ve gotten Robbie a little closer and helped him out.”