FBI Director James Comey has confirmed for the first time that the bureau is investigating possible ties between Republican Donald Trump's presidential campaign and Russia.

Comey and Admiral Mike Rogers, the director of the National Security Agency, made clear on Monday that their investigation of Moscow and November's US elections could last for months.

The two officials spent more than five hours before the House of Representatives Intelligence Committee in testimony marked by starkly partisan divides between the panel's majority Republicans and Democrats.

Comey refused to back away from his claim that Russian President Vladimir Putin did not simply want Democratic presidential candidate Hillary Clinton to lose the election; he wanted Donald Trump to win.

The committee is one of several in the US Congress investigating whether Russia tried to influence the election, mostly by hacking Democratic operatives' emails and releasing information. Russia denies the allegations.

Al Jazeera's Washington Editor James Bays said the statements by the intelligence officials were "embarrassing" for the Trump administration.

"That's something they don't want to hear in the White House," he said.

Comey confirmed that the FBI has been investigating since July possible Russian efforts to interfere in the election, including any cooperation between Trump's campaign and Moscow.

He said that while the Russian government wanted to hurt Clinton's campaign and help Trump's, intelligence agencies made no judgment on whether the efforts influenced the outcome.

Comey gave no details of the classified investigation and said the fact that it exists does not mean charges would be filed.

US intelligence agencies have concluded that Russia tried to help Trump by hacking leading Democrats.

'Preference for Trump'

"I think that was a fairly easy judgment for the [intelligence] community," he said. "Putin hated Secretary Clinton so much that the flip side of that coin was he had a clear preference for the person running against the person he hated so much."

Asked about Comey, White House spokesman Sean Spicer read a series of quotes from officials - some from the Obama administration - who have said they have seen no signs of collusion between Trump's campaign and Russia.

In a tweet before the hearing, Trump wrote: "The Democrats made up and pushed the Russian story as an excuse for running a terrible campaign."

OPINION: Why is Russia so happy with Trump?

Spicer said he was unaware of any White House official being under investigation by the FBI.

Trump has frequently urged better relations with Russia, which has been at odds with the United States over Ukraine and the Syrian civil war.

Representative Adam Schiff, the top Democrat on the intelligence committee, detailed activities by Trump associates with ties to Russia, including former campaign manager Paul Manafort and Michael Flynn, who was forced out as Trump's national security adviser after talking to the Russian ambassador and then misrepresenting the conversation to Vice President Mike Pence.

"Is it possible that all of these events and reports are completely unrelated and nothing more than an entirely unhappy coincidence? Yes, it is possible," Schiff said.

"But it is also possible, maybe more than possible, that they are not coincidental, not disconnected and not unrelated."

Wiretap claim

Comey also publicly challenged Trump's claim that former President Barack Obama wiretapped his 2016 campaign headquarters in Manhattan's Trump Tower.

Trump created a controversy in early March when he tweeted without giving evidence that Obama had wiretapped his campaign while the businessman competed against Clinton.

READ MORE: Donald Trump stands by phone-tapping claims

"With respect to the president's tweets about alleged wiretapping directed at him by the prior administration, I have no information that supports those tweets," Comey said.

Leon Panetta, a former US defence secretary and CIA director during the Obama administration, said in an interview that Trump should "acknowledge that he made a mistake, apologise to President Obama".