McCain, who was campaigning in this early voting state and didn't plan to vote on the bill containing the withdrawal timetable, said the consequences of withdrawal would be severe.
"If we leave Iraq there will be chaos, there will be genocide, and they will follow us home," the Arizona senator said, calling the war against al-Qaida "a struggle between good and evil."
On Wednesday, the House brushed aside a veto threat and passed legislation that would order President Bush to begin withdrawing troops from Iraq by Oct. 1.
As the furor grows over the firings of eight federal prosecutors, McCain also broke with President Bush, saying that Attorney General Alberto Gonzales should leave office.
"His best loyalty to the president would be served by stepping down," McCain said during a morning campaign stop.
McCain told CNN in a report aired late Wednesday that he was disappointed with Gonzales and that the attorney general should step down. "I think loyalty to the president should enter into his calculations," McCain said in the interview with Larry King.
McCain is the first Republican presidential contender to urge Gonzales to resign, and the fourth Republican senator to do so, joining Tom Coburn of Oklahoma, Gordon Smith of Oregon and John Sununu of New Hampshire. Several others have stopped short of demanding Gonzales's resignation but have harshly criticized his leadership.
Bush has given Gonzales a strong vote of confidence and the attorney general himself has vowed to remain in his post despite bipartisan criticism of his leadership. At a contentious Senate Judiciary Committee hearing last week, Gonzales claimed dozens of times that he couldn't recall key details about the firings or about a meeting that records show he attended.
On Thursday, McCain was joined at his campaign stop by Sen. Lindsey Graham, R-S.C., and bantered with reporters about Graham being the perfect replacement as attorney general.
"It would be a very popular move in Congress," McCain said. Graham laughed, but did not address the remark and the two quickly joked when asked about sharing a presidential ticket.
"I think he'd make a lousy vice president," Graham said.
McCain's sense of humor has been criticized twice in the past week. On Tuesday night, he joked on Comedy Central's "The Daily Show with Jon Stewart," that he had brought an explosive device back from Iraq as a gift for the show's host. Last week, while in South Carolina, McCain gave a rendition of the opening lyrics of the Beach Boys rock classic "Barbara Ann," calling the tune "Bomb Iran" and changing the words to "bomb, bomb, bomb, bomb, anyway, ah ..."
On Thursday, he said that people with military experience know that a sense of humor is vital.
"We veterans know how important a sense of humor is," he said, adding that critics have to "lighten up and get a life."
During his morning speech to about 150 voters, McCain lauded South Carolinians for their support of U.S. troops overseas and said he is a candidate who can wage war if necessary. "I know how to fight and I know how to make peace," McCain said, a day after formally declaring his second White House bid.
McCain, who planned a full day of campaigning in the state, made his remarks hours before Democratic candidates were to meet in South Carolina for their first debate of the 2008 election season.