Fresh from re-election, President Barack Obama's already full plate got fuller with the resignation of CIA chief David Petraeus over an extramarital affair, giving him another high-profile position to fill.

The revelation brought a startling end to the four-star general's stellar career, one so productive it had even sparked speculation he would one day run for the White House.

"After being married for over 37 years, I showed extremely poor judgment by engaging in an extramarital affair," the CIA director said in a message to staff that was released to the media Friday.

Obama acknowledged Petraeus's departure, praising his "intellectual rigor, dedication, and patriotism."

But there was no denying it added to the president's headache over the makeup of his new administration, which is already expected to lose heavyweights such as Secretary of State Hillary Clinton.

Obama purportedly had no inkling that the CIA chief was about to leave until Thursday morning and refused to accept it straight away, the New York Times reported.

"He was surprised, and he was disappointed," the Times quoted one senior administration official as saying. "You don't expect to hear that the Thursday after you were re-elected." The election was Tuesday.

As he heads into his second term, which starts in late January, Obama will likely also have to find replacements for Defense Secretary Leon Panetta and Treasury Secretary Tim Geithner.

Speculation is already rife about who will replace Clinton, who has stressed she wants to reclaim a private life put on hold by decades in the spotlight.

Now, adding to the rumor mill is talk of who might succeed Petraeus, a 60-year-old former paratrooper credited with turning around the Iraq war.

Michael Morell, Petraeus's deputy at the lead spy agency, will serve as acting director amid signs he might just be a placeholder.

Morell is expected to fill in for Petraeus at an upcoming hearing in Congress about the CIA's alleged failure to protect a US consulate in Libya from a deadly attack on September 11 that led to the deaths of four Americans, including the ambassador.

One name being floated is that of John Brennan, the White House counter-terrorism adviser and a CIA veteran who has played an instrumental role in Obama's drone war against Al-Qaeda militants.

Neither Petraeus nor the CIA explained exactly why he felt he had to step down over the affair, and whether his liaison presented a purely personal problem or raised security issues in his sensitive work as spy chief.

The affair came to light as the FBI was investigating whether a computer used by Petraeus had been compromised, the New York Times and other US media reported, citing government officials.

NBC News and other media reported the Federal Bureau of Investigation was investigating Paula Broadwell, co-author of a favorable biography of Petraeus, "All In: The Education of David Petraeus," for possible improper access to classified information.

Unnamed officials told the Times that Petraeus's lover was Broadwell, a former Army major who spent long periods interviewing Petraeus for her book. She offered no public comment on the revelations.

Experts noted that if Petraeus, a four-star general who retired to take the CIA job, had committed adultery while still in the army, he could have been court-martialed.

The most celebrated military officer of his generation, Petraeus, 60, took over at the CIA a little over a year ago. He was credited by some with rescuing a failing US war effort in Iraq in 2007, after then president George W. Bush ordered a surge of troops into the country.

Obama later turned to him to lead a similar surge of American forces in Afghanistan in 2010, leaving a top post as commander of all US forces in the Middle East to do so.

But Obama chose not to promote Petraeus to the US military's top job as chairman of the Joint Chiefs of Staff, as White House officials remained wary of the media-savvy general who had pushed for more troops and more time in the Afghanistan war.

His military background, however, sometimes clashed with the intelligence agency's culture and there was some friction with the congressional committees that oversee the spy services.

At the CIA, he had worked to shift the spy agency to a more "balanced" approach to intelligence gathering, after an intense focus on terror threats after the September 11, 2001 attacks, said Bruce Riedel, a former CIA officer and fellow at the Brookings Institution think tank.

"He had already begun to position the agency to live in the post-9/11 world," he told AFP.

Senator John McCain, a loyal supporter who championed the general's surge strategy in Iraq, heaped praised on Petraeus, who is married and has two children.

"General David Petraeus will stand in the ranks of America's greatest military heroes," he said.

The journal Foreign Policy, in a blog post, called Patraeus's downfall a "huge loss for the United States."

"He would have been a useful check on groupthink inside the Obama administration -- an independent voice for a White House often accused of being insular and one-dimensional," it said.

"Petraeus's exit leaves a bitter taste. We all make mistakes. Here's hoping he makes a comeback."