The deal is worth $22 million, a league source confirmed to ESPN's Jerry Crasnick, and could end up being worth $33 million over three years.
The team can buy out Gallardo for $2 million after two years or pick up a club option of a third year worth $13 million, the source said.
Gallardo and Baltimore had reportedly agreed to terms on a three-year contract worth $35 million on Saturday, but the deal stalled after the Orioles reviewed the right-hander's pre-signing physical.
"It was a little bit different, to be honest, but I'm just glad we were able to get something done,'' Gallardo said Thursday. "It's part of the process, to be honest. I think it's part of the situation, becoming a free agent, but everything for me, I'm past that.
"We had a little bit of contact since Day 1. That was pretty much it. As the offseason went on, it got a little more serious. I want to pitch for a team that wants me.''
Gallardo, who turns 30 later this month, is 102-75 with a 3.66 ERA in nine seasons, the first eight coming with the Milwaukee Brewers.
Last year, pitching for the Texas Rangers, he went 13-11 with a 3.42 ERA, but he struggled in the second half, posting a 1.72 WHIP and lasting six innings just twice in 14 outings. He made 33 starts, marking the seventh straight season in which he started at least 30 games and worked 180-plus innings.
As a result of signing Gallardo, who declined a qualifying offer from Texas, the Orioles must surrender the 14th overall pick in June's amateur draft.
"Yovani will be the first to tell you he's going to try to do his part and be somebody we are going to trust and depend on. Nothing more, nothing less,'' Orioles manager Buck Showalter said. "We feel good about that time of commitment for someone like him.''
To make room for Gallardo on the 40-man roster, the Orioles designated utilityman Efren Navarro for assignment.
Information from ESPN's Eddie Matz and Jerry Crasnick and The Associated Press was used in this report.