Bogota, Colombia — Not so long ago, Cesar Parra'sworld changed with a cup of coffee — a freshly brewed, richly aromatic ambrosia served at one of this nation's fast-multiplying quality cafes.

"It came as a shock, having a good cup," said Parra, 47, a late-to-the-game coffee lover who spoke on the sidelines of a master class for baristas. "I was born and raised in Colombia. And all my life, I'd been drinking bad coffee."

For decades, this South American nation harbored a dirty little secret. In the land of Juan Valdez and his mule, Conchita — the fictional characters from advertisements who have hooked the world on rich mugs of Colombian coffee since the 1950s — it was nearly impossible to get a good cup of Joe.

The reasons are well established. The finest arabica beans from Colombia's emerald hills were mostly exported, leaving domestic coffee consumers to drink the proverbial dregs. Some of the coffee consumed locally actually came from cheap imports from as far away as Vietnam. Then there's the way filtered coffee is prepared here. The most popular style is tinto — a weak and watery concoction with a shelf life rivaling Spam.

"Even at five-star hotels in Bogota, you'd have a hard time," said Roberto Velez, chief executive of the Colombian Coffee Growers Federation. "We grew the best. But Colombians just weren't used to drinking quality coffee."

Globalization is changing that — specifically a wave of well-traveled Colombian entrepreneurs who, along with a number of foreign investors, are upping the quality of domestic coffee roasting and brewing. Together, they are fomenting a revolution in Colombia's coffee-drinking culture.

In Latin America, the better-coffee trend is percolating well beyond Colombia's borders. Super­markets in Brazil were long known for peddling a few cheap, lower-quality brands. But as consumers there clamor for a better brew, grocery stores are stocking locally produced gourmet beans.

Panama, meanwhile, is world-famous for cultivating Geisha — a prized coffee variety known for its subtle, almost tea-like favor. Yet for years, Panama was as in­famous as Colombia for serving up bad brews at home. That has changed, however, with a new crop of "third wave" coffee houses — reflecting a movement to produce and serve artisanal coffee.

In Colombia, domestic consumption of coffee — which lagged global trends for years — is skyrocketing, with experts citing the wider availability of better-quality coffee as a major factor.

Hundreds of new cafes have opened in recent years, with much of that growth coming from just one chain, Tostao. Since opening in December 2015, the company has democratized good coffee, offering prices so low that even maids and construction workers can afford a quality cup.

Yet the most elaborate new brew houses are elevating coffee to an art form, replicating the almost laboratory-like cafes pioneered by hardcore java hipsters in such places as New York, Berlin, Seattle and Tokyo. The good coffee has excited the senses of Colombians like Parra, who feel as if they are discovering their nation's most famous (legal) export for the first time.

An aspiring cafe owner, Parra said he became inspired after sampling the brews at one of the capital's new high-style cafes. His obsession drove him one recent afternoon to downtown Bogota, where he joined 14 students for classes at Varietale. One of the capital's hippest coffee shops, it serves, among other things, blends produced via vacuum and heat in glass siphons.

For the attendees — from simple aficionados to baristas — the classes offer the kind of minutiae about coffee qualities typically reserved for agribusiness schools. In one exercise, students placed 12 grams of grounds from different batches into cups before dousing them with hot water. They smelled the bouquet, then slurped and spit, as if at a wine tasting.

"As drinkers, I think Colombians only now are really understanding what good coffee tastes like," Parra said.

Colombians began to get a taste of premium coffee at least as far back as the early 2000s, when Juan Valdez — the now-global chain established by the national coffee federation — began opening cafes. The quality of Colombian coffee beans was already on the rise. In the early 1990s, when coffee prices collapsed on the commodities markets, Colombia responded by encouraging its farmers to better compete globally by producing finer varieties of beans. The government has additionally deployed experts to help teach farmers to better judge well-balanced taste and acidity levels.

But experts say the spurt in quality coffee shops began more recently.

The idea came in large part from Colombian entrepreneurs who had traveled to Europe and the United States and experienced coffee-drinking epiphanies. Abel Calderon, co-owner of Varietale, for instance, opened his first branch in 2015 after sampling what Colombian coffee could taste like at cafes such as Storyville in Seattle.

"We had to taste our coffee outside of Colombia to appreciate what it could be like here," he said.

Pedro Gasca, a former executive with the Colombian airline Avianca, co-founded Tostao after visiting global chains like Pret a Manger.

The concept was tweaked for Colombia. Realizing that the majority of the high-end coffee shops here were priced out of reach for most Colombians, Tostao instead went for volume — selling coffee that has earned approving nods from specialists for as cheap as 40 cents a cup.

Coffee drinking per capita in Colombia still lags places such as the United States, France and Brazil. But between 2009 and 2014, the most recent data available, coffee consumption soared 33 percent in Colombia, compared with 15 percent globally. That rush to java is evident in Tostao's rapid growth. In just 20 months, it has leapt to 200 locations — becoming as ubiquitous in Bogota as Starbucks is in the United States.

"We discovered that Colombians — I mean all Colombians, including the working class — really wanted a good cup of coffee," Gasca said.

At the same time, international entrepreneurs have spotted the odd hole for better-quality coffee in Colombia's market. Starbucks arrived in 2014. Tyler Youngblood, a native Californian, launched a coffee-roasting operation in Colombia in 2010. His company, Azahar Coffee Co., opened its first Bogota coffee shop in a makeshift metal container in 2013. This month, it opened a far larger cafe.

The firm uses some of the highest-quality beans available — the kind almost always exported in the past.

"I think the point is that Colombians have a right to drink their own best coffee," Youngblood said.

Another boost for coffee culture, local entrepreneurs say, came from peace.

The official end last year of Colombia's half-century-long war with the left-wing FARC guerrillas, as well as an easing of paramilitary violence in some coffee-growing regions, has opened up swaths of the country to local farm-to-table restaurateurs and coffee shop owners, some of whom are striking deals directly with farmers.

Alejandro Gutierrez, chef at Salvo Patria — a Bogota restaurant that started as a coffee shop six years ago — recently tasted coffee grown and roasted in the battled-scarred Meta region. Meta is not one of the country's better-known coffee regions, and Gutierrez was surprised by the beans' quality. He ended up ordering batches for his restaurant, which lists coffee-growing regions for blends on its menu in the same way it does for wines.

"That whole state was FARC territory, and you wouldn't have thought about it before as an option for good coffee," he said. "But here you have this great coffee coming from there, and who knew? Well, now we know."

Wesley Tomaselli in Bogota and Anna Jean Kaiser in Rio de Janeiro contributed to this report.