Under a plea deal, the 25-year-old singer will avoid prison and will have no conviction on his record if he stays out of trouble for a year.
Clark County District Judge Jessie Walsh gave Mars, whose real name is Peter Gene Hernandez, probation, a $2,000 fine, 200 hours of community service at a nonprofit organization and eight hours with a drug counselor in Los Angeles. If he violates the terms of the agreement, Mars could face up to four years in state prison.
Walsh set a Jan. 18 date for Mars to return to court.
Mars acknowledged having 2.6 grams of cocaine when he was arrested in a bathroom early Sept. 19 after a nightclub performance at the Hard Rock Hotel & Casino in Las Vegas.
Police say he told the arresting officer he never used drugs before.
Mars, a Hawaii native, performed Sunday at the Grammys and took home the award for best male pop vocal performance for his song "Just The Way You Are." On Tuesday, his label announced that he would headline with recording artist Janelle Monae on a North American tour dubbed "Hooligans in Wondaland."
The Associated Press contributed to this story.