(Adds details, background)
BOGOTA, July 24 (Reuters) - Colombian state oil company Ecopetrol's consolidated net profit fell 2.5 percent in the second quarter from a year earlier to 3.65 trillion pesos ($2 billion), the company said on Tuesday, lower than analyst expectations.
Once seen as a failing state, Colombia began to turn its image around after a 2002 U.S.-backed security crackdown against leftist rebels made the country safer and opened up more areas to oil exploration and production.
The company said that Ecopetrol had faced some difficult operating conditions and lower international oil prices in the second quarter of the year - the results were substantially below the 4.28 trillion pesos expected by the market.
It was also lower than the first quarter when net profit rose 27.6 percent to 4.3 trillion pesos.
Ecopetrol said that consolidated operating profit rose 2.1 percent to 6.18 trillion pesos in the April-June period compared with 2011.
Earnings before interest, tax, depreciation and amortization fell 2.1 percent, good for an EBITDA margin of 45 percent compared with 47 percent a year before, the company said.
The company said that oil production by the group - which includes operations outside Colombia - went up 4.8 percent to 762,200 barrels of oil equivalent per day (boepd) in the second quarter versus the same period in 2011.
Production from Ecopetrol S.A. was 5.2 percent higher at 709,400 boepd in the period.
Colombia's national oil output has ramped up to historic records in the last few years as easing security concerns have allowed greater exploitation of heavy crude areas in addition to incremental production increases at existing fields.
Thanks to better security, the Andean country may see as much as $16 billion in foreign direct investment this year, up from nearly $15 billion last year, according to the government.
$1=1,790.39 Colombian pesos (Reporting by Jack Kimball; Editing by Gary Hill and Eric Meijer)