The judges scored it 29-28, 28-29, 29-28 for the underdog Lawler.
MacDonald (15-2) drew criticism from UFC president Dana White for his performance last time out in a win over Jake Ellenberger. But he got plenty of love to start from the crowd at the MGM Grand Garden Arena.
He walked out to cheers and Rihanna's "We Found Love." The ovation grew as he was introduced in the cage and there were chants of "Rory, Rory" within the first minute.
The chant changed to "Robbie, Robbie" in the third as Lawler (22-9 with one no contest) knocked the Canadian down and punished him. A tired MacDonald managed a late takedown and some ground and pound of his own, finishing the fight with a flurry of blows.
The main event at the MGM Grand Garden Arena pitted welterweight champion Georges St-Pierre against No. 1 contender Johny (Bigg Rigg) Hendricks.
The card celebrated the UFC's 20-year anniversary. Brazilian jiu-jitsu ace Royce Gracie won UFC 1, an eight-man elimination tournament, on Nov. 12, 1993, at McNichols Sports Arena in Denver.
The 24-year-old MacDonald, who came into the fight a 4-1 favourite, is third among welterweight contenders while Lawler is No. 10.
A native of Kelowna, B.C., who trains alongside GSP in Montreal, MacDonald has said he won't fight St-Pierre.
Lawler was aggressive in a close first round with MacDonald looking to use movement, kicks and jabs to blunt his opponent's attack or spin out of range. Lawler kept coming in the second round but seemed to be tiring. And when he slowed, MacDonald countered. He also scored a takedown to take the round.
Lawler came at MacDonald early but the Canadian took him down, earning boos. Referee Mario Yamasaki stood them up and it was MacDonald's turn to take blows on the bottom when it went back to the ground.
The crowd clearly wanted to see a slugfest. But instead there was a delay as MacDonald was allowed to recover from a poke in the eye.
Earlier, Tyron Woodley knocked out veteran welterweight Josh Koscheck at 4:38 of the first round.
Koscheck (19-8) was driven backwards by an early right. And referee Herb Dean hovered over the fighters as Woodley battered Koscheck on the ground later in the first round. But the veteran hung on.
Woodley (12-2) ended it brutally, crumpling Koscheck with a right to the chin and then hitting him with another on the way down.
It was the 23rd UFC fight for Koscheck, a cast member of Season 1 of "The Ultimate Fighter." He had lost his last two — to Lawler and Hendricks.
Russian flyweight Ali (Puncher) Bagautinov won his 10th straight via a 29-28, 29-8, 30-27 decision over seventh-ranked Tim Elliott.
Bagautinov (12-2) landed a lot of punches but had to fight off a second-round guillotine from the unorthodox and durable Elliott, who was not afraid to absorb several strikes to land one of his own.
Bagautinov got the win but never quite solved Elliott (10-4-1) and ate a big knee as the fight ended.
The undercard featured more perspiration than inspiration although lightweight Donald (Cowboy) Cerrone and welterweight Rick (The Horror) Story were on their game.
Cerrone (21-6 with one no contest) used his striking superiority to batter Evan Dunham (14-5) before submitting him in the second round. Cerrone, ranked No. 10 among 155-pound contenders, stuffed Dunham's takedowns and then scored one of his own before locking in a triangle choke at three minutes 49 seconds of the second round.
Both men needed a victory, having each lost two of their last three bouts.
"This fight was big for me," said Cerrone. "I told myself that if I didn't go out there and perform like I know I'm capable of then I would've retired."
Story (16-8) dominated with punishing strikes and leg kicks en route to a unanimous 30-27 decision over Brian (Bad Boy) Ebersole (50-16-1 with one no contest). Ebersole, his chest hair shaved into an arrow pointing upwards, made as if Story wasn't hurting him but clearly took a lot of punishment.
Ebersole later said he has been fighting through back pain in recent bouts.
Brazilian middleweight Thales Leites used his grappling skills to have his way with Ed (Short Fuse) Herman (21-9 with one no contest) on the ground and win a unanimous 30-27 decision in a gruelling bout.
Leites (22-4) is now 2-0 in his second stint with the UFC, faring poorly in a 2009 title shot to Anderson Silva at UFC 97 in Montreal in his first go-round.
Bantamweight Sergio (The Phenom) Pettis (10-0), the younger brother of lightweight champion Anthony (Showtime) Pettis, won his UFC debut via a 30-27, 30-27, 29-28 decision over a hard-nosed Will Campuzano (13-5).
Welterweight Jason (The Kansas City Bandit) High (19-4) won a unanimous 29-28 decision over UFC newcomer Anthony (The Recipe) Lapsley (25-6 with two no contests) in a fight contested mainly on the ground.
Mexican bantamweight Erik (Goyito) Perez looked impressive in earning a unanimous 30-27 decision over Edwin (El Feroz) Figueroa in a spirited scrap.
For Perez (14-5), it was a return to the win column after a loss to Takeya Mizugaki in August snapped a run of eight straight victories. Figueroa (9-4), who has now lost three straight, earned points for making it through the three rounds. He said later his knee "popped out" in the second round.
Light-heavyweight Gian Villante (11-4) posted his first UFC win with a TKO over (Donnybrook) Cody Donovan at 1:22 of the first round to open the card.
The crowd included Arnold Schwarzenegger, who drew cheers when shown on the big screens.