The answer by @peterh is accurate on the factual information about the Einstein Field Equations and that it describes how the matter distribution affects spacetime. There is more that may be added that hopefully will help understand more of it.
First, just to be totally clear, gravity as described by GR (general relativity, through Einsteins Field Equations) is due to the curvature of spacetime, which is caused by any kind of matter energy. Thus, you can say matter-energy causes gravity, which is the curvature of spacetime. As the spacetime curves matter then follows the curves in spacetime that are the shortest path between 2 points, called the geodesics. Yes, one creates gravity and spacetime, which affects everything in it. It is a set of very nonlinear equations. Thus, in this geometrical description of gravity, there is no force. We still call it the effect the gravity, or the gravitational field effect
Still, it turns out that the geometric description, when the gravitational field is not too strong, can be described as a force and Newton's equations and description of gravity are a very good approximation in those cases. The gravitational force of the earth can for the most part be described that way, and all orbits computed accurately enough that way. The same is true for the sun. There are some minor effects that Newtons equations cannot describe in those cases:
1) there is a small time dilation effect, where time is just a tiny bit slower on the surface of the earth than it is where the GPS satellites keep track of time, and those are then slightly adjusted. 2) the orbits of the planets have their perihelion shift just slightly, and it's been observed.
GR describes those perfectly.
Your question of why the critical density affects whether the uNiverse keep expandinged forever (an open universe), collapses back (closed universe, Big Crunch), or just barely keeps going (flat) is actually a little more complex. Remember the Einstein Field Equations. They can be written as
Einstein Tensor = k X [Energy-momentum tensor + dark energy term]
(The dark energy term was originally on the left side, as a cosmological constant term. Different words for the same thing)
When one solves this set of equations (there are 10 independent equations, the different components of the Tensors), for homogeneous isotropic spacetimes (a very limited set, called Robertson Walker solutions, really 3, with positive, negative or zero SPATIAL curvature), you get the Friedman equations. Those relate the density of matter energy to the curvature. The critical density is simply that density which makes the SPATIAL curvature zero, or flat, a so called flat universe (words again, it really is only the spatial part that has no curvature, there is an expansion which makes the spacetime curved).
So if the density is equal to the critical density, spacetime is so called flat. It has been measured and estimated to be so within about 2%. And yes about 70% of that density is the dark energy, and about 25% dark matter. Both dark matter and dark energy are mysterious, but there is evidence of their existence.
For dark matter it is well determined that they are around and inside galaxies, and help keep them as such. Galaxies rotate too fast to not have their stars fly away due to the centrifugal effect, and that has been used to determine the density of dark matter around and in galaxies. It is thought they are massive particles that are remnants of the Big Bang because they interact very weakly (no strong nuclear nor electromagnetic interactions, only the weak nuclear and gravity) with themselves and other matter. The specific particles have not yet been directly detected, so there can always be some surprises.
Dark energy is even more mysterious. Try some of the answers on this site about it or Wikipedia for a quick summary. We don't know what it is, but there is also evidence that it exists. Galaxies further away from us are expanding faster, accelerating, and the numerical observations are consistent with a constant dark energy density at about 70% of critical. When and if we find out what it really is there can also be surprises. See also https://en.m.wikipedia.org/wiki/Dark_energy
In both cases, the most accurate measurements are due to the cosmological microwave background. See https://en.m.wikipedia.org/wiki/Cosmic_microwave_background.
It predicts the cosmological parameters very accurately, but still some uncertainties
So, yes, energy and matter density affects spacetime, and for the universe its expansion. If the total energy density is critical it is a flat universe.