Physics- Something that's been holding back me for a while

It’s been quite some time that I’ve been trying to get something done, but I am getting stuck on a pretty ridiculous obstacle.
All I wanted to do was a plataformer, with physics similar to Terraria (not the building/break part, just the physics). i.e 2D grid-like world with moving entities.

I think the part I’m messing up is the algorithm, can you guys help me get past this?
Here’s what I thought while writing this thread:
On each game loop:

  • Iterate through all entities
    – Update their positions based on their current motions (posX += motionX and posY += motionY)
    – Check if they collide with the grid-world (blocks) and update their positions so they don’t overlap with the blocks
  • Iterate through all entities a second time
    – Inside the current entity iteration, iterate with all entities that are not the current one
    — Check if they collided, if they do, do the following:
    ---- Teleport the entity to where the collision happened [¹]
    ---- Give damage or something, basically call some onCollidedWith method, make it invencible for 1 second or 2

I just improvised this algorithm, because I don’t have anything else in mind? What should I do to have a properly functional 2d grid world?
Btw this part: [¹] - Brings me some confusion because, since there are many entities, I think it would cause some physical bugs in case 3 entities were moving and 2 collided where there shouldn’t have a collision due to another collision that should have taken place before the previous collision.
This is very hard to explain but basically, what confuses me is the order in which the collision responses are to be executed.
Besides, my algorithm also looks very slow (iterate through all entities 3 times?).

My last resort is to humbly ask for a less poor algorithm, that would be responsive but at the same time not overwhelmingly hard to implement, this all must be very simple and the fact that I’ve been stuck past this point has been bugging me so much. Any input is appreciated.