INDIANAPOLIS, AUG. 23 -- The 10th Pan American Games concluded peacefully tonight, save for a riot of balloons and fireworks, making it one of the few events in this gathering of 27 countries and roughly 6,000 athletes that went off without incident, good or bad.

By the time the Pan Am flame was extinguished and various Western Hemisphere flags were raised and lowered in an elaborate bilingual affair at the Hoosier Dome, the Games had become an event that was part headache and part happening. Sometimes thrilling on the athletic fields, it was also at times a wearying experience off them.

The host country dominated the medal count as U.S. teams won a total of 369 awards, 168 of them gold, 118 silver and 83 bronze. Cuba was second with 175 medals -- 75 gold, 52 silver and 48 bronze. But off the field, six athletes were disqualified after testing positive for drug use, and politics inevitably intruded, whether it was Chile threatening to boycott the opening ceremonies, or Cuba threatening to boycott the closing ones.

"Today is both happy and sad," said Mario Vazquez Rana, president of the Pan American Sports Organization, as he officially closed the Games. "Sad because the Games are finished, happy because they remain in history. But more importantly, in our hearts."

The role of Indianapolis as host marked the first time since 1959 the Games were held in this country, and Cuba's presence marked the first major visit by its athletic delegation since diplomatic relations between the two nations were broken in 1963.

But there was also tension between the Cuban delegates and anti-Castro protesters, and when it was revealed that one of the bands chosen to play tonight included two Cuban-American exiles, Cuban delegates threatened not to attend. That ended peacefully as well, for the Cuban delegation showed up with one of its high-ranking government officials, Jose Ramon Fernandez Alvarez, minister of education and sport. His presence signified the passing of the Games to Cuba, which will next host them in Havana in 1991.

While the United States won by far the most medals here, it was with some relief that the national team closed the athletic portion of the Games as well, because the final day was not entirely a good one for U.S. athletes. Earlier today, the women's basketball team, as expected, won a gold medal and the men's volleyball squad won its first Pan Am gold in 20 years, but there were also some upsets.

The U.S. basketball team, led by Navy's David Robinson, had swept through most of the competition with relative ease, only to suffer a stunning upset in today's final, losing to Brazil, 120-115.

In boxing, the United States won just one gold medal. Cuba won five more final bouts to set a Pan Am record total of 10 gold medals. That bettered Argentina's mark of eight set in 1951 in Buenos Aires. Only Chicago's Kelcie Banks won gold for the United States, defeating the Dominican Republic's Emilio Villegas. The United States settled for four more silver and four bronze.

"I could not have envisioned this," said U.S. Coach Roosevelt Sanders.

Brazil struck again in tennis, where Al Parker of the United States lost his final match to gold medalist Fernando Roese in straight sets, 6-4, 6-2. The ambidextrous Luke Jensen of Southern Cal, won the bronze medal. The U.S. women did not win a singles medal.

The women's gymnastics team finished with a flourish, winning seven medals in individual events, three of them gold. Kristie Phillips, 15, set a Games record in the floor exercise with a score of 19.538 to win the gold, and added a bronze medal in the vault.

But that only partly made up for her disappointment at losing the all-around competition Saturday to teammate Sabrina Mar, and falling off the balance beam during the team competition. After carrying the torch during the opening ceremonies, it was a discouraging competition for her.

"My motivation went after I fell on the beam," she said. "The wanting it, like I usually do, just wasn't there."

Melissa Marlowe won the gold in the uneven bars, and Kelly Garrison-Steves won the gold in the balance beam. Mar won silver medals in the uneven bars and the floor exercise, and a bronze in the balance beam.

Mar's performance today capped her comeback from a broken leg in 1986 and a congenital back problem that almost ended her career.

"This was only my second major meet this year," Mar said. "I knew I could hit {my routines}, but I didn't know if I could do it under the pressure."

The U.S. women's basketball team defeated Brazil by a predictably lopsided 111-87, but not without some close moments. The Brazilians were a fast, talented team led by Hortencia Marcari's game-high 30 points, and Paula Silva's 26 points. Six U.S. players were in double figures, led by Katrina McClain's 30 points.

The U.S. men's volleyball team outlasted Cuba, 15-12, 15-7, 15-17, 10-15, 15-7, in a match lasting more than 2 1/2 hours. The Americans first took a 2-0 lead in games and had a chance to win the match in the third game before Cuba rallied. Tied, 7-7, in the final game, the Americans scored the next eight points.

Karch Kiraly led the U.S. team with 33 kills. After he scored the final stuff block of Joel Despaigne's spike, Kiraly was the first in line to shake the hands of the Cuban players.

"I wanted to win so badly," said Despaigne, who had 38 kills. "I did all I could, but we still lost."

The competition concluded, the athletes converged on the Hoosier Dome, where they watched multicolored fountains and pinwheeling spotlights, listened to a children's choir and danced to Miami Sound Machine's Latin beat.