Oil rose slightly on Tuesday after U.S. stock markets bounced off their lows amid lingering optimism that the government's plan to unburden banks of soured assets could help shore up the ailing economy.

The gains were limited, however, as dealers awaited a round of U.S. oil inventory data that analysts expected would show a an increase in crude stockpiles.

U.S. light crude for May delivery rose 18 cents to settle at $53.98 a barrel, after hitting a near-three-month high of $54.20 earlier in the day. London Brent crude rose 3 cents to $53.50 a barrel.

The stock market bouncing off its low helped crude firm up here at the end. Everybody is waiting for inventories to see if supplies are up again, said Gene McGillian, analyst at Tradition Energy in Stamford, Connecticut.

U.S. stock markets edged downward, but were off their lows after Federal Reserve Chairman Ben Bernanke said investors who participate in the government's plan to soak up toxic assets from banks would not be retroactively penalized.

Analysts said they expected oil inventory data to be released by the American Petroleum Institute on Tuesday afternoon and the U.S. Energy Information Administration on Wednesday to show a 1.2 million barrel build in crude stockpiles.

Energy demand in the world's biggest consumer has been hard-hit by the economic meltdown, buffering inventory levels, and global consumption has been shrinking for the first time in a quarter century.

Oil prices have climbed from under $33 last December, partly due to aggressive supply cuts from OPEC, but remain almost $100 below last summer's peak.

Oil price gains were also limited after media reported Tuesday that China's refined fuel stocks rose 11 percent in February despite a sharp post-holiday rebound in domestic sales, suggesting demand in the world's No. 2 consumer may be weaker than thought.

A strike by oil workers in Brazil entered its second day Tuesday, but output from South America's second-biggest oil producer was unaffected according to state oil company Petrobras.

Meanwhile, Nigerian oil unions on Tuesday called off plans for a workers' strike this week after the government promised to do more to improve security in the restive Niger Delta.

(Editing by Jim Marshall)