By Kylie MacLellan

LIVERPOOL, England (Reuters) - Prime Minister Theresa May repeatedly failed to back her predecessor David Cameron in his fight to keep Britain in the European Union and hampered his attempts to rein in migration, according to extracts from two books about the referendum.

May, who served as interior minister under Cameron and succeeded him as prime minister when he resigned after Britain's vote to leave the EU, backed staying in the bloc but was largely absent from the campaign.

The two books come as May faces the complex task of leading negotiations over Britain's EU divorce, having divulged little on her intended strategy.

Extracts from a book by Sunday Times political editor Tim Shipman said that May refused to support Cameron in seeking to take a harder line on immigration in his deal with Brussels to reform Britain's relationship with the EU.

May told Cameron that he should not press ahead with demands for an "emergency brake" to limit the number of EU migrants coming to Britain because Germany would not back it, the newspaper reported.

A separate book written by Cameron's former head of communications Craig Oliver details more than 10 occasions when May declined to back Cameron during the referendum campaign.

Cameron's team dubbed her "Submarine May" for disappearing when she was needed, Oliver said.

"Her sphinx-like approach is becoming difficult, with the press questioning which way she will jump," Oliver wrote in the book, extracts of which were published in the Mail on Sunday newspaper.

Oliver said that Cameron had asked May to back his plan to crack down on migrants coming to Britain to claim social security payments but she issued a statement describing it simply as "the basis for a deal".

The author also said that Boris Johnson -- a leading "out" campaigner and now foreign minister -- "wobbled" over backing a Brexit and told Cameron that he would be supporting the leave campaign only nine minutes before announcing it to the media.

In his text message to Cameron, Boris made clear he did not expect to win, saying Brexit would be "crushed", Oliver said.

(Editing by David Goodman)