SAN FRANCISCO — The Cubs started the day two games in the hole in a three-game series, then demoted an infielder, lost their starting pitcher because of illness and, in the fifth inning, lost two more players to an ejection and a sore knee.

Talk about no chance for the worst road team in the National League.

But thanks to three early home runs and perhaps the unlikeliest four-inning start of the year, by Tyler Chatwood, the Cubs salvaged a 4-1 victory Wednesday in San Francisco against the hottest team in the majors.

And, more important, they might have salvaged their sanity just ahead of a day off and a critical stretch on the schedule.

“I can’t deny that helps,” Cubs manager Joe Maddon said after losing scheduled starter Jon Lester to a fever, Anthony Rizzo to a fifth-inning ejection and third baseman Kris Bryant to a sore knee. “With everything that had been going on, sending Addison [Russell] out, Jonny being ill, Rizzo getting kicked out, KB having to come out of the game, if you get on an airplane and not winning that game, that’s where the dialogue becomes fabricated in a negative way. And it’s very difficult to control that.

“Now we can get on the airplane, get back home, have an off day, believe it or not, and regroup a little bit.”

Lester, who got sick Tuesday, showed just enough signs of recovery by Wednesday night that the Cubs scheduled him to start Saturday in Milwaukee. Kyle Hendricks opens that series Friday, and Jose Quintana starts Sunday’s finale.

Bryant aggravated his achy knee when his cleat caught the mat while he was taking indoor batting practice before the game. After his two-run homer in the third gave the Cubs the lead, he left the game after a strikeout in the fifth, on a double switch. He said the knee was well enough after treatment that he expects to return Friday “and be ready to go.”

Bryant’s exit came right about the time Rizzo was “surprised” by an ejection for grousing about an earlier called strike as he struck out swinging to end the fifth.

“If [what I said] was a ‘magic word,’ I’d probably be ejected from 90 games a year,” said Rizzo, who added he’s not even sure what words he used. “Losing the first two here with the off day tomorrow, there’s no way I wanted to get ejected from the game. I’m happy the boys picked me up and picked KB up and picked Jonny up.”

Chatwood, who got a heads up Tuesday that he might be pitching but didn’t know for sure until about two hours before game time Wednesday, struck out five, walked one and allowed just one run in four innings — after pitching just two innings total over the previous 26 days.

“I was just excited to pitch,” he said.

Maddon had hoped to get three decent innings from Chatwood under the circumstances.

“He did wonderfully,” Maddon said.

This and that

Cole Hamels (oblique), who fared well in a 35-pitch minor-league rehab start Tuesday, originally had targeted Sunday as a possible return date. He’s scheduled to stay with Class AAA Iowa long enough to throw a between-starts bullpen session Thursday before the Cubs chart his next step — either one more rehab start or a return from the injury list next week in St. Louis.

• Maddon said he remains “cautiously optimistic” that 2016 World Series MVP Ben Zobrist will return from his personal leave this season. But the Cubs don’t expect it until rosters expand in September.