The nucleus of an atom is composed of neutrons and protons.
Around this nucleus swirls a cloud of electrons. Why are the electrons there? They are attracted and held in place by an electromagnetic interaction with the nucleus.
The nucleus has a net positive charge, while electrons carry a negative charge. And opposite charges attract. The protons have the positive charge, while the neutrons, as their name suggests, have no charge at all.
If you have three protons in the nucleus, you'll need three electrons to make what's called a "stable" atom.