It was an illegal war triggered by Robert McNamara while he was SECDEF. In the late 1950s and early '60s there was paranoia by capitalist nations, including the US, that the Communists would spread all over the world if they were not stopped in southeast Asia. It was called the domino effect.
And the French fighting in Vietnam were losing badly. When they lost in Dien Bien Phu, they basically surrendered and pulled out leaving a political vacuum.
So with illusions of grandeur, MaNamara concocted a false raid on an American destroyer by some Vietnamese small boats. And using that trumped up excuse, Nixon, Westmoreland, and Nixon kept throwing more Americans into the war because the US, like the French, was losing the war.
The US ended up with over 55,000 dead because Nixon did not want to be the "...first US President to lose a war." The quote is from Nixon's infamous tapes.
So the short answer is: we entered it because of unfounded paranoia, we stayed in it because Nixon and Westmoreland did not want to be the first Americans to lose a war...because of their egos. The irony...we lost the war anyway.