Maryland State Senator Lewis P Firey introduced a plan in 1864 to the Maryland Senate to establish a cemetery for the men who died during the 1862 Maryland Campaign. A committee made up of the House and Senate met, "to inquire into the propriety of purchasing, on behalf of the State, a portion of the battle-field of Antietam, not exceeding twenty acres, for the purposes of a State and National Cemetery, in which the bodies of our heroes who fell in that great struggle and are now bleaching in the upturned furrows, may be gathered for a decent burial, and their memories embalmed in some suitable memorial." An eligible sight was selected on the battlefield and the state purchased eleven and a quarter acres on March 23rd 1865 for $ 1,161.75.
Aaron Good and Joseph Gill had spent the years since the battle locating and recording the names of the dead. The two men used diaries, letters, marks left on grave, receipts, photos, and interviews with survivors to make identifications. With contribution coming in from 18 Northern states, the money was raised to have the dead moved and reburied in the Antietam National Cemetery. The original plan called for both Union and Confederate dead to be buried, but the Southern states where unable to send any money for the re-interment their soldiers. The burials were completed by September 1867, and done mostly by discharged soldiers.
On September 17th 1867, the fifth anniversary of the Battle of Antietam, President Andrew Jackson gave the speech dedicating the Cemetery. He said as part of that speech, "When we look on yon battlefield, I think of the brave men who fell in the fierce struggle of battle, and who sleep silent in their graves. Yes, many of them sleep in silence and peace within this beautiful enclosure after the earnest conflict has ceased."
If you are interested in reading more about the cemetery, I recommend looking at Cemetery Dedication 1867