I respectfully disagree with the above answer. The Alien and Sedition Acts were passed due to an ongoing dispute with France which caused everyone at the time to believe that war was inevitable, so much so that President John Adams had contacted former President Washington and asked him to command the troops in battle. They had nothing to do with a Federalist attempt to silence the Democratic Republicans, as is implied above.
France was angry with the U.S. because of a treaty negotiated by John Jay with Great Britain, France's arch rival. France accused the U.S. of disloyalty, broke diplomatic relations, and had begun to seize American vessels. When Charles Cotesworth Pinckney was sent to France as ambassador, the government there refused to accept him and ordered him to leave. The situation grew worse when President Adams sent three ambassadors to discuss a solution with the French, but they were told they needed to pay a bribe before they would even be allowed to meet with the French ambassador, Charles Tallyrand. This was the infamous XYZ affair, the names given to the anonymous French representatives at the conference.
When war seemed inevitable, the Alien and Sedition Acts were passed as a war time measure. They extended the time when one must live in the U.S. to become a citizen; allowed the President to deport aliens he considered dangerous; allowed the President to expel aliens at will during time of war; and prohibited writing or publishing anything false, scandalous, or malicious against the government.
While these Acts seem strange, it should be remembered that Congress also passed a Sedition Act in 1918 when the U.S. was engaged in World War I. That Act was upheld by then Chief Justice Oliver Wendell Holmes by way of the famous "clear and present danger" doctrine.
The Alien and Sedition Acts came about because the American political parties did not yet know how to deal with the very serious differences that existed between them.
As the 1790s came to an end, the Federalists and Democratic-Republicans were just coming to exist as political parties. They had very serious differences over things like whether to side with England or with France and whether the US should be agricultural or industrial.
They also did not have any sort of a long history of political tolerance like we have now. They were just getting started with democracy and were still prone to think that anyone who disagreed with them was a traitor. Because of these factors, the Federalists passed the Alien and Sedition Acts to try to suppress the opposition party.