KANSAS CITY, Mo. (AP) Alex Smith performed his job flawlessly against his former team Friday night.

Then, the Chiefs quarterback sat back and watched his understudies.

First-round draft pick Patrick Mahomes II led the Kansas City Chiefs to a third-quarter touchdown, and outplayed veteran backup Tyler Bray, before the San Francisco 49ers rallied behind their own second-stringers for a 27-17 victory in the preseason opener for both teams.

"I'm right there, right? I'm watching intently," said Smith, who was 4 for 6 for 48 yards in his only series. "We're a group. We're a team. So certainly following those guys, for sure. The situations they get - if there is anything I can offer, trying to help out any way I can."

Smith hit speedster Tyreek Hill for a 32-yard gain on the first play of the game, and Spencer Ware capped a 75-yard march with a short TD run to give the Chiefs a 7-0 lead.

Then it was Mahomes' turn.

The first QB taken by the Chiefs in the first round in 34 years, he drew perhaps the biggest roars of the night. And while his first long completion was wiped out by a holding penalty, Mahomes later took advantage of a blocked punt with a short touchdown throw to fellow rookie Marcus Kemp.

Mahomes was 7 of 9 for 49 yards as he duels with Bray for the No. 2 job.

"Definitely, Adrenaline was pumping," he said. "You're living out a dream. You're doing something you imagined in backyards when you were a little kid, so I definitely was excited."

San Francisco rookie C.J. Beathard experienced many of the same feelings in his debut.

He wound up with a better outcome, too.

The third-round pick hit Kendrick Bourne for a 46-yard TD pass in the fourth quarter, then found him for a tying 2-point conversion. The Chiefs promptly fumbled the ball back and Beathard added a short TD pass to Tyler McCloskey with 10:41 left to give the 49ers the lead for good.

"There's still so many things to learn from this tape," Beathard said. "There's things that I could improve on just by watching the film, and I'm excited to get back and watch it."

Beathard outplayed both quarterbacks ahead of him on the depth chart.

Brian Hoyer failed to make new 49ers coach Kyle Shanahan feel good about giving the longtime NFL journeyman the starting job early in training camp. He was 1 of 4 for 3 yards in two series.

Matt Barkley got the first shot after Hoyer and led San Francisco to two field goals, playing roughly two quarters. He was 10 of 17 for 168 yards without any major mistakes.

"You worry about what you can control," Hoyer said. "Go back and watch the film and make the corrections. The good thing was we saw that second group come in and kind of pick up what we needed to go to and really execute the offense. They did a good job."

BRAY'S NIGHT: First off the bench for Kansas City, Bray had an 83-yard TD pass to Chris Conley wiped out by offensive pass interference and an errant throw picked off. He was 5 of 8 for 63 yards.

HYDE'S BACKUP: Running back Carlos Hyde carried twice for San Francisco before giving way to Matt Breida and Joe Williams, rookies competing for the No. 2 job. Williams appeared to do more with fewer chances, showing an impressive burst in the open field.

FICKEN DOES KICKIN: Sam Ficken handled kicking duties for Kansas City while Cairo Santos deals with a groin injury. The former Penn State star hit a 45-yard field goal in the third quarter.

WELCOME BACK: 49ers LB NaVorro Bowman and Chiefs counterpart Derrick Johnson were back after tearing their Achilles' tendons last season. Bowman hurt his in October and Johnson hurt his in December.

"For the little bit of plays I played, it just felt good to get back out there, and have another year," Bowman said. "You know, live up to what I've built for myself, see what this team has to offer and what we can get better at for later weeks."