The San Francisco 49ers and Chicago Bears swapped the Nos. 2 and 3 picks in the NFL draft, and the Bears used the second selection on quarterback Mitchell Trubisky of North Carolina.

In swapping spots with the Bears, the 49ers get Chicago’s third- and fourth-round picks (Nos. 67 and 111) in this draft and a third-rounder in 2018.

With the third pick, the 49ers chose defensive lineman Solomon Thomas of Stanford — the highest pick of a Cardinal player in any draft. He played just two seasons at Stanford.

Trubisky told ESPN after his selection that he had no idea the swap was happening and that he did not get a call to alert him to his selection.

“I didn’t think I was going to get picked until the commish made the call,” he said. “It was crazy. It’s a dream come true. It’s as surreal as it gets.”

Trubisky, who had just 13 starts in college, is the highest drafted quarterback by the Bears in the common draft era and first quarterback taken by the Bears since Rex Grossman in 2003.

The Bears had a clear need at quarterback after the club released Jay Cutler. However, most expected them to wait to address the position until Day 2. Veteran Mike Glennon, who the Bears signed in free agency, is scheduled to earn $16 million guaranteed in 2017.

Bears general manager Ryan Pace announced earlier in the offseason that Glennon is the team’s unquestioned starter, but Glennon’s long-term future in Chicago now looks bleak.

Meanwhile, recently hired 49ers GM John Lynch selected a player from his alma mater and, believe it or not, a former classmate.

For the Niners, Thomas will be expected to instantly improve a defense that finished last in the NFL in 2016 in yards allowed, rushing yards allowed and was fifth-worst in the NFL in pressures generated per dropback.

The 49ers have now used their top pick in each of the past three drafts on the defensive line, having selected Arik Armstead in 2015 and DeForest Buckner last year. Thomas has been projected as a left defensive end in coordinator Robert Saleh’s 4-3 defensive scheme with the versatility to move to the three-technique defensive tackle spot in passing situations.

Thomas could also theoretically play the right defensive end spot, also known as the “Leo” or “Elephant,” the position where the best pass rusher is expected to line up. At his pro day in March, 49ers coach Kyle Shanahan said he believed Thomas was capable of playing all over the defensive line.

“I believe he can line up probably anywhere inside that he wants,” Shanahan said.