RIO DE JANEIRO — Brazil’s oil production is falling, casting doubt on what was supposed to be an oil bonanza. Imports of gasoline are rising rapidly, exposing the country to the whims of global energy markets. Even the nation’s ethanol industry, once envied as a model of renewable energy, has had to import ethanol from the United States.

Half a decade has passed since Brazilians celebrated the discovery of huge amounts of oil in deep-sea fields by the national oil company, Petrobras, triumphantly positioning the country to surge into the top ranks of global producers. But now another kind of energy shock is unfolding: the colossal company, long known for its might, is losing the race to keep up with the nation’s growing energy demands.

Saddled with a nationalist mandate to buy ships, oil platforms and other equipment from lethargic Brazilian companies, the oil giant is now facing soaring debt, major projects mired in delays and older fields, once prodigious, that are yielding less oil. The undersea bounty in its grasp also remains devilishly complex to exploit.

Now, instead of symbolizing Brazil’s rise as a global powerhouse, Petrobras embodies the sluggishness of the nation’s economy itself, which, after racing ahead at 7.5 percent in 2010, slowed to less than 1 percent last year, eclipsed by growth in other Latin American nations like Mexico and Peru.