MANCHESTER, N.H.  Senator Hillary Rodham Clinton of New York rode a wave of female support to a surprise victory over Senator Barack Obama in the New Hampshire Democratic primary on Tuesday night. In the Republican primary, Senator John McCain of Arizona revived his presidential bid with a Lazarus-like victory.

The success of Mrs. Clinton and Mr. McCain followed their third- and fourth-place finishes in the Iowa caucuses last week. Mrs. Clinton’s victory came after her advisers had lowered expectations with talk of missteps in strategy and concern about Mr. Obama’s momentum after his first-place finish in Iowa. Her team is now planning to add advisers and undertake a huge fund-raising drive to prepare for a tough and expensive fight with Mr. Obama in the Democratic nominating contests over the next four weeks.

Mr. McCain had pursued a meticulous and dogged turnaround effort: his second bid for the White House was in tatters last summer because of weak fund-raising and a blurred political message, leading him to fire senior advisers and refocus his energy on New Hampshire.

Several New Hampshire women, some of them undecided until Tuesday, said that a galvanizing moment for them had been Mrs. Clinton’s unusual display of emotion on Monday as she described the pressures of the race and her goals for the nation  a moment Mrs. Clinton herself acknowledged as a breakthrough.