Crude oil prices on both sides of the Atlantic ended with moderate gains on Tuesday, supported by a stock market advance and worries over Egypt, but were limited by a strong U.S. dollar and as supplies were brought back online.

Spread trading trumped trading in the straight oil contracts, which were lackluster in thin volume, one analyst said.

The spread between the U.S. August and September oil contracts <CLQ3-U3> widened by some 30 cents to a high of 57 cents after Tuesday's settlement. This helped further backwardation on the oil price futures curve, seen when prompt-month prices are higher than those further along the curve.

Traders guessed that a fund or another entity was betting on a large draw in crude supplies when inventory data is reported later this afternoon, making oil for the closer delivery months more valuable.

Traders awaited data expected to show a decline in crude oil stocks on Tuesday from the American Petroleum Institute and on Wednesday from the U.S. government.

Brent crude oil futures ended the day 38 cents higher at $107.81 per barrel. U.S. crude oil futures settled 39 cents higher at $103.53, after trading as low as $102.31.

Fears that violence in Egypt could ignite conflict in the broader Middle East, which pumps a third of the world's oil, continued to lend support to oil prices.

While oil prices had shaved some gains, Brent was still hovering at a three-month high and U.S. crude at a 14-month high.

"The majority of last week's near $5 gain is on the back of geopolitical risk premium," said Gene McGillian, analyst with Tradition Energy in Stamford, Connecticut.

The U.S. dollar index hit a fresh three-year high against a basket of currencies, creating headwinds for oil prices. A good start to the U.S. earnings season underpinned equities, which supported crude oil prices.

Commodities priced in dollars become more expensive for holders of other currencies as the dollar strengthens, weakening demand.

The spread between U.S. gasoline futures and heating oil <1RB-HOQ3> had narrowed to its smallest point in one month, reflecting the need for traders to square positions after the previous session, Walter Zimmermann, chief technical analyst for United-ICAP, said.

On Monday, gasoline futures rallied to seven-week high while heating oil hit a more than three-month high at $3.00 a gallon.

"RBOB really got hit hard relative to distillate yesterday but has gained all of it back," Zimmermann said.

Gasoline futures settled 4 cents higher at $2.92 a gallon, and heating oil ended virtually flat at $2.98.

The spread between global benchmark Brent crude oil and U.S. benchmark West Texas Intermediate <CL-LCO1=R> had levelled out to around $4.15 to $4.30 per barrel after narrowing to $3.09 last Wednesday. The spread settled at $4.28.

Improved supply from elsewhere in the Middle East helped push Brent oil prices lower for now. Libya's major Sharara oilfield will resume operations, and the flow of crude from Kirkuk in Iraq to the port of Ceyhan in Turkey will resume in two to three days after being interrupted for weeks due to a pipeline leak.

The U.S. Energy Information Administration slightly tightened its 2014 oil demand outlook but left the balance of the year unchanged.