In Race 1, Checa won in Utah for the fifth time in five years with an overpowering performance.
The reigning world champion easily defeated Melandri by 2.313 seconds and appeared to set himself up perfectly for an afternoon sweep.
In Race 2, however, Checa spun down after opening a big lead midway through the 64-mile contest.
Melandri seized the moment.
He stayed close to the leaders and passed Great Britain's Jonathan Rea on the final lap to score his second win of the season.
Melandri trailed Rea by nearly a half second with two laps remaining, but he didn't panic.
"I just tried to stay calm and get a good feeling about catching Jonathan," he said.
Melandri cut Rea's lead in half on the next-to-last lap before pushing forward and winning for the second time in his young career.
"I was making some mistakes at the end," Rea said. "... But it's so nice to be on the podium. Congratulations to Marco. Good job."
In his quest for a sweep in the second race, Checa was 1.346 seconds in front of Great Britain's Tom Sykes after only three laps.
At the back of the 24-racer field, however, Japan's Hiroshi Aoyama shredded a tire, crashed, spilled oil on the track and caused a 60-minute delay.
The restart didn't seem to bother Checa.
He quickly grabbed the lead and, within four laps, he extended his advantage over Melandri to 1.468 seconds.
It looked like Checa was headed to another easy victory when he crashed with 13 laps remaining, opening the door for Melandri and the BMW Motorrad Motorsports team.
"BMW has so many fans all over the world," Melandri said. "To give them a victory here is amazing."
In Race 1, Checa seized control early and rolled to victory aboard his Ducati 1098R motorcycle for Althea Racing.
"It is a happy moment for me," he said.
Checa stalked Sykes and Melandri for the first six laps before grabbing the lead and gradually pulling away.
"I tried to make life not easy for him," Melandri said. "But Carlos was running very strong."
Following Checa and Melandri, Max Biaggi of Italy ended up in third place. He also finished third in the second race.
"I am not super happy," Biaggi said. "But not too bad."
Pole-sitter Jakub Smrz of the Czech Republic was not a serious factor in either race.
In the opener, he got off the starting line a bit slowly and was beaten into the first turn. He was fifth after the first lap and never threatened the front-runners while finishing sixth.
In the nightcap, Smrz placed ninth.
Meanwhile, Salt Lake City's Shane Turpin turned in a commendable performance after accepting a wild-card invitation in the WSBK event in his hometown.
Turpin placed 18th and 19th, respectively.